快速在https上从不同位置提供文件

时间:2015-07-06 00:42:33

标签: node.js express amazon-ec2 angular-fullstack

我正在运行一个基于angular-fullstack应用程序松散的应用程序。它有一个http服务器和一个具有相同快递应用程序的https服务器。即使我运行NODE_ENV="production" node server/app.js,我的应用也能在我的本地计算机上以http或https运行。但是,当我将dist文件夹推送到我的AWS ec2实例时,该应用仅适用于http://example.com,而不适用于https。

在https地址,我得到Error: ENOENT, stat 'client/index.html' at Error (native)。我没有客户端文件夹,我的客户端代码(如index.html)位于名为public的文件夹中。我不明白为什么这些内容在http中正确提供但不是https,如果有人可以帮助我,我会很感激。

//Server/app.js file
var app = express();

var httpsServer = require('https').createServer(credentials, app);
var httpServer = require('http').createServer(app);
httpsServer.listen(httpsPort, config.ip, function () {
  console.log('https Express server listening on %d, in %s mode', httpsPort, app.get('env'));
});
httpServer.listen(httpPort, config.ip, function () {
  console.log('http Express server listening on %d, in %s mode', httpPort, app.get('env'));
});



var env = app.get('env');
app.set('views', config.root + '/server/views');
app.engine('html', require('ejs').renderFile);
app.set('view engine', 'html');
app.use(compression());
app.use(bodyParser.urlencoded({ extended: false }));
app.use(bodyParser.json());
app.use(methodOverride());
app.use(cookieParser());
app.use(passport.initialize());
console.log(env)
if ('production' === env) {
  app.use(favicon(path.join(config.root, 'public', 'favicon.ico')));
  console.log(path.join(config.root, 'public'));
  app.use(express.static(path.join(config.root, 'public')));
  app.set('appPath', config.root + '/public');
  app.use(morgan('dev'));
}

if ('development' === env || 'test' === env) {
  console.log('i am overwriting everything');
  app.use(require('connect-livereload')());
  app.use(express.static(path.join(config.root, '.tmp')));
  app.use(express.static(path.join(config.root, 'client')));
  app.set('appPath', 'client');
  app.use(morgan('dev'));
  app.use(errorHandler()); 
}

env记录为'production'path.join(config.root, 'public')记录到/home/ubuntu/www/public/ I am overwriting everything永远不会记录。

1 个答案:

答案 0 :(得分:0)

在您推入服务器之后,它看起来可能正在运行您的development.js。为了防止它阅读您的开发,请尝试在package.json中添加一个启动脚本。

"scripts": {
    "start": "NODE_ENV="production" node server/app.js"
}