I am running an app that is loosely based off the angular-fullstack app. It has both an http server and an https server with the same express app. My app runs fine on my local machine, in http or https, even when I run NODE_ENV="production" node server/app.js
. However, when I push the dist folder to my AWS ec2 instance, the app works only for http://example.com
, not https.
At the https address, I get Error: ENOENT, stat 'client/index.html' at Error (native)
. I do not have a client folder, my client code such as index.html is in a folder named public. I do not understand why this content is served correctly in http but not https and would grateful if someone could help me out.
//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
logs as 'production'
.
path.join(config.root, 'public')
logs to /home/ubuntu/www/public/
I am overwriting everything
never logs.