-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathstart.js
57 lines (46 loc) · 1.58 KB
/
start.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
'use strict'
const express = require('express')
const bodyParser = require('body-parser')
const {resolve} = require('path')
const passport = require('passport')
// Bones has a symlink from node_modules/APP to the root of the app.
// That means that we can require paths relative to the app root by
// saying require('APP/whatever').
//
// This next line requires our root index.js:
const pkg = require('APP')
const app = express()
if (!pkg.isProduction && !pkg.isTesting) {
// Logging middleware (dev only)
app.use(require('volleyball'))
}
module.exports = app
// We'll store the whole session in a cookie
.use(require('cookie-session') ({
name: 'session',
keys: [process.env.SESSION_SECRET || 'an insecure secret key'],
}))
// Body parsing middleware
.use(bodyParser.urlencoded({ extended: true }))
.use(bodyParser.json())
// Authentication middleware
.use(passport.initialize())
.use(passport.session())
// Serve static files from ../public
.use(express.static(resolve(__dirname, '..', 'public')))
// Serve our api
.use('/api', require('./api'))
// Send index.html for anything else.
.get('/*', (_, res) => res.sendFile(resolve(__dirname, '..', 'public', 'index.html')))
if (module === require.main) {
// Start listening only if we're the main module.
//
// https://nodejs.org/api/modules.html#modules_accessing_the_main_module
const server = app.listen(
process.env.PORT || 1337,
() => {
console.log(`--- Started HTTP Server for ${pkg.name} ---`)
console.log(`Listening on ${JSON.stringify(server.address())}`)
}
)
}