This repository was archived by the owner on Mar 26, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapp.js
More file actions
51 lines (38 loc) · 1.46 KB
/
app.js
File metadata and controls
51 lines (38 loc) · 1.46 KB
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
/// ShipShape > app
/// The main app entry point. Links up all the other stuff.
const express = require('express');
const app = express();
const morgan = require('morgan');
const path = require('path');
const bodyParser = require('body-parser');
const routers = {
game : [ '/game', require('./app/routers/game.js') ],
maps : [ '/maps', require('./app/routers/maps.js') ],
index : [ '/', require('./app/routers/index.js') ]
};
// Determine whether or not we are running in a development environment.
let dev = process.env.NODE_ENV != 'production';
// Use Morgan for logging (even in production).
app.use(morgan('dev'));
// Configure views and the view engine.
app.set('view engine', 'ejs');
app.set('views', 'app/views');
app.set('view options', {
delimiter: '$'
});
// Attach helpers for EJS views.
app.locals.helpers = require('./app/ejs-helpers.js');
app.locals.require = require;
// Parse form submissions.
app.use(bodyParser.urlencoded({ extended: false }));
// Connect routers.
for (let index = 0; index < Object.keys(routers).length; index++) {
let router = routers[Object.keys(routers)[index]];
app.use(...router);
}
// Serve resource files that have been processed.
app.use('/res', express.static(path.join(__dirname, 'res')));
// Listen on port 8080, or what is specified in the PORT environment variable.
let port = process.env.PORT || 8080;
let server = app.listen(port);
console.log(`Running ShipShape server on port ${port}.`)