-
Notifications
You must be signed in to change notification settings - Fork 1
/
server.js
34 lines (27 loc) · 959 Bytes
/
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
const express = require('express');
const bodyParser = require('body-parser');
var path = require("path");
var request = require('request');
const forceSsl = require('force-ssl-heroku');
// Set up the Express app
const app = express();
app.use(forceSsl);
// Set up static files
app.use(express.static('build'));
// Use body-parser to parse HTTP request parameters
app.use(bodyParser.json());
app.use(bodyParser.urlencoded({ extended: false }));
// Error handling middleware
app.use((err, req, res, next) => {
console.log(err); // To see properties of message in our console
res.status(422).send({error: err.message});
});
var port = process.env.PORT || 3000;
// Starts the Express server, which will run locally @ localhost:3000
app.listen(port, () => {
console.log('App listening on port 3000!');
});
// Serves the index.html file (our basic frontend)
app.get('*',(req, res) => {
res.sendFile('index.html', {root: __dirname + '/build/'});
});