-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathserver.js
58 lines (48 loc) · 1.89 KB
/
server.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
58
// Main entry point for the Connect My Dots server.
const bodyParser = require('body-parser');
const express = require('express');
const pg = require('pg');
const pgStore = require('connect-pg-simple');
const session = require('express-session');
const createApiRoutes = require('./server/api');
const createAuthRoutes = require('./server/auth');
// Compose a postgres session store class
const PgSessionStore = pgStore(session);
// This is the server for
const APP_NAME = 'Connect My Dots';
// We're using an Express.js node server which was really easy
// to get up and running on Heroku.
const app = express();
app.set('port', process.env.PORT || 5000);
// Configure our server to read JSON and urlencoded requests
app.use(bodyParser.json({limit: '50mb'}));
app.use(bodyParser.urlencoded({limit: '50mb', extended: true, parameterLimit: 50000}));
// Enable sessions (so users can log in)
app.use(session({
store: new PgSessionStore({ pg }),
name: 'cmd-session',
secret: process.env.SESSION_SECRET,
resave: false,
saveUninitialized: false,
}));
// It doesn't do much yet - just serves our static-built app
// from the build directory.
app.use(express.static(`${__dirname}/build`));
// We depend on this static build running before the server
// starts, in the npm postinstall hook or by some other means.
// See package.json's "scripts" key and this article
// https://devcenter.heroku.com/articles/node-best-practices#hook-things-up
// for more details.
// The root route returns the index page for our single-page app.
app.get('/', (request, response) => {
response.sendfile('index.html');
response.type('text/html');
});
// Add auth routes (sign in, sign out, etc)
createAuthRoutes(app);
// Add api routes (save map, load map, etc)
createApiRoutes(app);
// And finally we start listening on the port!
app.listen(app.get('port'), () => {
console.log(`${APP_NAME} is running on port ${app.get('port')}`);
});