2016-04-18 14:07:11 -04:00
|
|
|
var express = require('express');
|
|
|
|
var proxy = require('express-http-proxy');
|
|
|
|
var webpackDevMiddleware = require('webpack-dev-middleware');
|
|
|
|
var webpack = require('webpack');
|
|
|
|
|
|
|
|
var compiler = webpack(require('../webpack.config.js'));
|
|
|
|
var handler = require('./handler');
|
|
|
|
var log = require('./log');
|
2018-03-09 08:49:56 -05:00
|
|
|
var routes = require('../src/routes.json').concat(require('../src/routes-dev.json'))
|
|
|
|
.filter(route => !process.env.VIEW || process.env.VIEW === route.view);
|
2016-04-18 14:07:11 -04:00
|
|
|
|
|
|
|
// Create server
|
|
|
|
var app = express();
|
|
|
|
app.disable('x-powered-by');
|
|
|
|
|
|
|
|
// Server setup
|
|
|
|
app.use(log());
|
|
|
|
|
|
|
|
// Bind routes
|
2016-04-09 12:04:39 -04:00
|
|
|
routes.forEach(route => {
|
2016-04-18 14:07:11 -04:00
|
|
|
app.get(route.pattern, handler(route));
|
2016-04-09 12:04:39 -04:00
|
|
|
});
|
2016-04-18 14:07:11 -04:00
|
|
|
|
2018-07-18 11:49:52 -04:00
|
|
|
var middlewareOptions = {};
|
|
|
|
if (process.env.USE_DOCKER_WATCHOPTIONS) {
|
|
|
|
middlewareOptions = {
|
2018-07-18 11:37:58 -04:00
|
|
|
watchOptions: {
|
|
|
|
aggregateTimeout: 500,
|
|
|
|
poll: 2500,
|
|
|
|
ignored: ['node_modules','build']
|
|
|
|
}
|
2018-07-18 11:49:52 -04:00
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
app.use(webpackDevMiddleware(compiler, middlewareOptions));
|
2016-04-18 14:07:11 -04:00
|
|
|
|
|
|
|
var proxyHost = process.env.FALLBACK || '';
|
|
|
|
if (proxyHost !== '') {
|
|
|
|
// Fall back to scratchr2 in development
|
|
|
|
// This proxy middleware must come last
|
|
|
|
app.use('/', proxy(proxyHost));
|
|
|
|
}
|
|
|
|
|
|
|
|
// Start listening
|
|
|
|
var port = process.env.PORT || 8333;
|
|
|
|
app.listen(port, function () {
|
|
|
|
process.stdout.write('Server listening on port ' + port + '\n');
|
|
|
|
if (proxyHost) {
|
|
|
|
process.stdout.write('Proxy host: ' + proxyHost + '\n');
|
|
|
|
}
|
|
|
|
});
|