Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
// 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
You can’t perform that action at this time.