-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathserver.js
44 lines (32 loc) · 1.2 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
import express from 'express';
import morgan from 'morgan';
import path from 'path';
import authentication from './routes/authentication';
var bodyParser = require('body-parser');
// eslint-disable-next-line
import React from 'react'; // jsx rendered as React.createElement
let __dirname = path.resolve();
var app = express();
var router = express.Router(); //Instance of Express Router
// Configure app to use bodyParser()
// This will let us get the data from a POST request
app.use(bodyParser.urlencoded({ extended: true }));
app.use(bodyParser.json());
app.use('/css', express.static(__dirname + '/public/css/'));
app.use('/api/login', authentication);
app.use(express.static(path.join(__dirname, 'public')));
router.get('/', function(req, res) {
res.json({ message: 'API works'});
});
app.use('/api', router);
// morgan logs requests to the console
app.use(morgan('dev'));
// send all requests to index.html so browserHistory in React Router works
app.get('*', function (req, res) {
res.sendFile(path.join(__dirname, 'public', 'index.html'));
});
// listen
var PORT = process.env.PORT || 8080;
app.listen(PORT, function() {
console.log('Production Express server running at localhost:' + PORT);
});