Using a single index file. Updated servers. Removed duplicate npm scripts.

This commit is contained in:
William Welling
2017-03-22 08:05:27 -05:00
parent 9dd08c8597
commit 9496bf7e42
7 changed files with 71 additions and 78 deletions

View File

@@ -41,6 +41,7 @@ app.engine('.html', createEngine({
]
}));
app.set('port', process.env.PORT || 3000);
app.set('address', process.env.ADDRESS || '127.0.0.1');
app.set('views', __dirname);
app.set('view engine', 'html');
app.set('json spaces', 2);
@@ -72,16 +73,26 @@ app.get('/data.json', serverApi);
app.use('/api', createMockApi());
function ngApp(req, res) {
res.render('index', {
req,
res,
// time: true, // use this to determine what part of your app is slow only in development
async: true,
preboot: true,
baseUrl: '/',
requestUrl: req.originalUrl,
originUrl: `http://localhost:${app.get('port')}`
function onHandleError(parentZoneDelegate, currentZone, targetZone, error) {
console.warn('Error in SSR, serving for direct CSR');
res.sendFile('index.html', { root: './src' });
return false;
}
Zone.current.fork({ name: 'CSR fallback', onHandleError }).run(() => {
res.render('index', {
req,
res,
// time: true, // use this to determine what part of your app is slow only in development
async: true,
preboot: true,
baseUrl: '/',
requestUrl: req.originalUrl,
originUrl: `http://${app.get('address')}:${app.get('port')}`
});
});
}
/**
@@ -102,5 +113,5 @@ app.get('*', function(req, res) {
// Server
let server = app.listen(app.get('port'), () => {
console.log(`Listening on: http://localhost:${server.address().port}`);
console.log(`Listening on: http://${server.address().address}:${server.address().port}`);
});