-
Notifications
You must be signed in to change notification settings - Fork 0
/
server.js
56 lines (41 loc) · 1 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
/**
* This is just a dummy server to facilidate our React SPA examples.
* For a more professional setup of Express, see...
* http://expressjs.com/en/starter/generator.html
*/
import express from 'express';
import path from 'path';
const app = express();
/**
* Anything in public can be accessed statically without
* this express router getting involved
*/
app.use(express.static(path.join(__dirname, 'public'), {
dotfiles: 'ignore',
index: false
}));
/**
* Always serve the same HTML file for all requests
*/
app.get('*', function(req, res, next) {
console.log('Request: [GET]', req.originalUrl)
res.sendFile(path.resolve(__dirname, 'index.html'));
});
/**
* Error Handling
*/
app.use(function(req, res, next) {
console.log('404')
let err = new Error('Not Found');
err.status = 404;
next(err);
});
app.use(function(err, req, res, next) {
res.sendStatus(err.status || 500);
});
/**
* Start Server
*/
const port = 3000;
app.listen(port);
console.log('Serving: localhost:' + port);