Build setting some configs. Configs used by server.

This commit is contained in:
William Welling
2017-03-24 20:54:24 -05:00
parent 9b23393121
commit 2974d8aab1
17 changed files with 103 additions and 95 deletions

View File

@@ -24,7 +24,7 @@ import { MainModule } from './platform/modules/node.module';
// Routes
import { routes } from './server.routes';
import { config } from './config';
import { EnvConfig } from './config';
// enable prod for faster renders
enableProdMode();
@@ -42,8 +42,9 @@ app.engine('.html', createEngine({
// stateless providers only since it's shared
]
}));
app.set('port', process.env.PORT || 3000);
app.set('address', process.env.ADDRESS || '127.0.0.1');
app.set('port', process.env.PORT || EnvConfig.ui.port || 3000);
app.set('address', process.env.ADDRESS || EnvConfig.ui.address || '127.0.0.1');
app.set('views', __dirname);
app.set('view engine', 'html');
app.set('json spaces', 2);
@@ -59,13 +60,13 @@ function cacheControl(req, res, next) {
res.header('Cache-Control', 'max-age=60');
next();
}
// Serve static files
app.use('/assets', cacheControl, express.static(path.join(__dirname, 'assets'), { maxAge: 30 }));
app.use('/styles', cacheControl, express.static(path.join(__dirname, 'styles'), { maxAge: 30 }));
app.use(cacheControl, express.static(path.join(ROOT, 'dist/client'), { index: false }));
//
/////////////////////////
// ** Example API
// Notice API should be in aseparate process
@@ -87,11 +88,11 @@ function ngApp(req, res) {
req,
res,
// time: true, // use this to determine what part of your app is slow only in development
async: true,
preboot: true,
baseUrl: '/',
async: EnvConfig.universal.async,
preboot: EnvConfig.universal.preboot,
baseUrl: EnvConfig.ui.nameSpace,
requestUrl: req.originalUrl,
originUrl: `http://${app.get('address')}:${app.get('port')}`
originUrl: EnvConfig.ui.baseUrl
});
});
@@ -115,5 +116,5 @@ app.get('*', function(req, res) {
// Server
let server = app.listen(app.get('port'), app.get('address'), () => {
console.log(`Listening on: http://${server.address().address}:${server.address().port}`);
console.log(`Listening on: ${EnvConfig.ui.protocol}://${server.address().address}:${server.address().port}`);
});