-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathindex.js
31 lines (25 loc) · 859 Bytes
/
index.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
'use strict';
const path = require('path');
const httpLib = require('http');
const express = require('express');
const bodyParser = require('body-parser');
const app = express();
const http = httpLib.Server(app);// eslint-disable-line new-cap
// parse application/json
app.use(bodyParser.json());
app.use(bodyParser.urlencoded({extended: false}));
// Deliver the public folder statically
app.use(express.static('public'));
// This tells the server to listen
var port = 3000;
http.listen(port, function () {
console.log('Example app listening on port ' + port + '!');
});
/*
* This tells the server to always serve index.html no matter what,
* excluding the previously defined api routes. This is so we can use
* react-router's browserHistory feature.
*/
app.get('*', function (req, res) {
res.sendFile(path.join(__dirname, '/public/index.html'));
});