1

我正在运行一个松散地基于 angular-fullstack 应用程序的应用程序。它同时有一个 http 服务器和一个 https 服务器,它们具有相同的 express 应用程序。我的应用程序在我的本地机器上运行良好,在 http 或 https 中,即使我运行NODE_ENV="production" node server/app.js. 但是,当我将 dist 文件夹推送到我的 AWS ec2 实例时,该应用程序仅适用于http://example.comhttps,而不适用于 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从不记录。

4

1 回答 1

0

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

"scripts": {
    "start": "NODE_ENV="production" node server/app.js"
}
于 2016-03-16T16:35:16.943 回答