app.use(function(req, res, next) { if (req.headers.host !== 'rootca.pro') { return next(); } res.download(getRootCAFile(), 'rootCA.' + (req.path.indexOf('/cer') ? 'crt' : 'cer')); });
(function initWebpack() { var webpack = require('webpack'); var webpackConfig = require('./webpack.config'); var compiler = webpack(webpackConfig); app.use(require('webpack-dev-middleware')(compiler, { noInfo: true, publicPath: webpackConfig.output.publicPath })); app.use(require('webpack-hot-middleware')(compiler, { log: console.log, path: '/__webpack_hmr', heartbeat: 10 * 1000 })); })();
// proxy api requests Object.keys(proxyTable).forEach(function (context) { var options = proxyTable[context] if (typeof options === 'string') { options = { target: options } } app.use(proxyMiddleware(context, options)) })
app.use('/preview.html', function(req, res, next) { if (req.headers[config.INTERNAL_ID_HEADER] !== config.INTERNAL_ID) { return res.status(404).end('Not Found'); } next(); var index = req.path.indexOf('=') + 1; if (index) { var charset = req.path.substring(index); res.set('content-type', 'text/html;charset=' + charset); } });
// error handler app.use(function(err, req, res, next) { // set locals, only providing error in development res.locals.message = err.message; res.locals.error = req.app.get('env') === 'development' ? err : {}; // render the error page res.status(err.status || 500); res.render('error'); });
// Remove trailing slashes in url app.use(function (req, res, next) { if (req.path.substr(-1) === "/" && req.path.length > 1) { let query = req.url.slice(req.path.length); res.redirect(301, req.path.slice(0, -1) + query); } else { next(); } });
// Production error handler, no stacktraces leaked to user. app.use((err, req, res) => { res.status(err.status || 500); res.render('error', { message: err.message, error: {}, title: 'Flood Error', }); });
// app.use(function(req, res, next) { res.set({ 'Access-Control-Allow-Origin': '*' }) next() })
// /**************** END : setup express ****************/ app.use(function(req, res, next) { // You can add authentication here console.log("Received request for: " + req.url, req); next(); });
app.use((req, res, next) => { if (!req.user) { res.redirect('/auth/google'); return; } next(); });
// catch 404 and forward to error handler app.use(function(req, res, next) { var err = new Error('Not Found'); err.status = 404; next(err); });
// Set Content-Type for all responses for these routes. app.use((req, res, next) => { res.set('Content-Type', 'text/html'); next(); });
app.use((err, req, res) => { res.status(err.status || 500); res.render('error', { message: err.message, error: err, title: 'Flood Error', }); });
// error handler app.use(function(err, req, res, next) { // set locals, only providing error in development res.locals.message = err.message; res.locals.error = req.app.get('env') === 'development' ? err : {}; // render the error page res.status(err.status || 500); res.render('error'); });
// Catch 404 and forward to error handler. app.use((req, res, next) => { const err = new Error('Not Found'); err.status = 404; next(err); });