-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapp.js
More file actions
32 lines (25 loc) · 857 Bytes
/
app.js
File metadata and controls
32 lines (25 loc) · 857 Bytes
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
const bodyParser = require('body-parser');
const express = require('express');
const moment = require('moment');
const http = require('http');
const path = require('path');
const api = require('./api');
const app = express();
app.disable('x-powered-by');
app.use(bodyParser.urlencoded({ extended: false }));
app.use(bodyParser.json());
// Log every request
app.use((req, res, next) => {
console.log(moment().format(), req.method, req.url);
next();
});
// API requests go through the submodule
app.use('/api', api);
// If a static file exists for the URL then send it
app.use(express.static(path.join(__dirname, 'static'), { index: false }));
// For all other URLs send the frontend `index.html`
app.get('/*', (req, res) => {
res.redirect('index.html');
});
http.createServer(app).listen(3000);
console.log('HTTP server running on port', 3000);