X-Git-Url: https://git.auder.net/images/pieces/Cwda/bd.svg?a=blobdiff_plain;f=server%2Fapp.js;h=df15fa20ed4f2902ba1b31fcce2d15f99a1d142b;hb=934f7f70431e9892b3ea48ba199356b4f24eaf1b;hp=eced7d331972e86f8b3d49b1a1a04cdcf3120112;hpb=0da7d5b86e5c0e0acf2fb763f93ac3b3509c066b;p=vchess.git diff --git a/server/app.js b/server/app.js index eced7d33..df15fa20 100644 --- a/server/app.js +++ b/server/app.js @@ -11,12 +11,9 @@ let app = express(); app.use(favicon(path.join(__dirname, "static", "favicon.ico"))); if (app.get('env') === 'development') -{ // Full logging in development mode app.use(logger('dev')); -} -else -{ +else { // http://dev.rdybarra.com/2016/06/23/Production-Logging-With-Morgan-In-Express/ app.set('trust proxy', true); // In prod, only log error responses (https://github.com/expressjs/morgan) @@ -28,17 +25,24 @@ else app.use(express.json()); app.use(express.urlencoded({ extended: false })); app.use(cookieParser()); -app.use(express.static(path.join(__dirname, 'static'))); //client "prod" files +// Client "prod" files: +app.use(express.static(path.join(__dirname, 'static'))); +// Update in progress: +app.use(express.static(path.join(__dirname, 'fallback'))); // In development stage the client side has its own server -if (params.cors.enable) -{ +if (params.cors.enable) { app.use(function(req, res, next) { res.header("Access-Control-Allow-Origin", params.cors.allowedOrigin); res.header("Access-Control-Allow-Credentials", true); //for cookies - res.header("Access-Control-Allow-Headers", - "Origin, X-Requested-With, Content-Type, Accept"); - res.header("Access-Control-Allow-Methods", "GET, POST, OPTIONS, PUT, DELETE"); + res.header( + "Access-Control-Allow-Headers", + "Origin, X-Requested-With, Content-Type, Accept" + ); + res.header( + "Access-Control-Allow-Methods", + "GET, POST, OPTIONS, PUT, DELETE" + ); next(); }); } @@ -47,16 +51,15 @@ if (params.cors.enable) const routes = require(path.join(__dirname, "routes", "all")); app.use('/', routes); -// catch 404 and forward to error handler +// Catch 404 and forward to error handler app.use(function(req, res, next) { next(createError(404)); }); -// error handler +// Error handler app.use(function(err, req, res, next) { res.status(err.status || 500); - if (app.get('env') === 'development') - console.log(err.stack); + if (app.get('env') === 'development') console.log(err.stack); res.send( "