Created
July 27, 2020 18:11
-
-
Save tonyspiro/09c96eb3a1fa7328a6994623c50880d1 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// app-server.js | |
import express from 'express' | |
import hogan from 'hogan-express' | |
import http_module from 'http' | |
import bodyParser from 'body-parser' | |
import compression from 'compression' | |
import session from 'express-session' | |
import config from './config' | |
import cors from 'cors' | |
const app = express() | |
app.use(cors({credentials: true, origin: true})) | |
app.use(bodyParser.json()) | |
app.use(compression()) | |
app.engine('html', hogan) | |
app.set('views', __dirname + '/views') | |
app.set('port', process.env.PORT || 3000) | |
app.use(express.static(__dirname + '/public')) | |
app.set('trust proxy', 1) // trust first proxy | |
app.use(session({ | |
secret: 'keyboard cat', | |
resave: false, | |
saveUninitialized: true | |
})) | |
app.use((req, res, next) => { | |
if (req.url === '/favicon.ico') | |
return res.end() | |
// Set global variables | |
res.locals.year = new Date().getFullYear() | |
// Set dev | |
if (process.env.NODE_ENV === 'development') | |
res.locals.is_dev = true | |
next() | |
}) | |
const partials = { | |
header: 'partials/header', | |
footer: 'partials/footer' | |
} | |
require('./routes')(app, config, partials) | |
const http = http_module.Server(app) | |
http.listen(app.get('port'), () => { | |
console.info('==> 🌎 Go to http://localhost:%s', app.get('port')); | |
}) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment