Skip to content

Instantly share code, notes, and snippets.

Created July 27, 2020 18:11
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
Save tonyspiro/09c96eb3a1fa7328a6994623c50880d1 to your computer and use it in GitHub Desktop.
// 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.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
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
const partials = {
header: 'partials/header',
footer: 'partials/footer'
require('./routes')(app, config, partials)
const http = http_module.Server(app)
http.listen(app.get('port'), () => {'==> 🌎 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