This repository has been archived by the owner on May 3, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.min.js
1 lines (1 loc) · 1.88 KB
/
app.min.js
1
"use strict";var server,port,debug=require("debug")("app-science:server"),cookieParser=require("cookie-parser"),compression=require("compression"),createError=require("http-errors"),_require=require("underscore"),each=_require.each,express=require("express"),logger=require("morgan"),helmet=require("helmet"),path=require("path"),http=require("http"),app=express(),staticify=require("staticify")(path.join(__dirname,"public")),render=require("./render.min"),routeList=render.route,pageList=render.page,normalizePort=function(e){var r=parseInt(e,10);return isNaN(r)?e:0<=r&&r};port=normalizePort(process.env.PORT||"8080"),app.locals={getVersionedPath:staticify.getVersionedPath},app.use(helmet()),app.use(compression()),app.use(staticify.middleware),app.use(function(e,r,s){e.url=e.url.replace(/\/([^\/]+)\.[0-9a-f]+\.(css|js|jpg|png|gif|svg|cache)$/,"/$1.$2"),s()}),app.use(express.static(path.join(__dirname,"public"),{maxAge:86400..toString()})),app.set("views",path.join(__dirname,"views")),app.set("view engine","pug"),app.set("view cache",!0),app.use(logger("dev")),app.use(express.json()),app.use(express.urlencoded({extended:!1})),app.use(cookieParser()),each(routeList,function(i,e){app.get(e,function(e,r){var s=pageList[i],t=s[1]||"template/page",p=s[0];r.render(t,p)})}),app.use(function(e,r,s){s(createError(Number(404)))}),app.use(function(e,r,s,t){s.status(e.status||500),s.render("error",render.error)}),app.set("port",port),(server=http.createServer(app)).listen(port),server.on("error",function(e){if("listen"!==e.syscall)throw e;var r="string"==typeof port?"Pipe "+port:"Port "+port;switch(e.code){case"EACCES":console.error(r+" requires elevated privileges"),process.exit(1);break;case"EADDRINUSE":console.error(r+" is already in use"),process.exit(1);break;default:throw e}}),server.on("listening",function(){var e=server.address(),r="string"==typeof e?"pipe "+e:"port "+e.port;debug("Listening on "+r)});