-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathserver.js
48 lines (37 loc) · 1.34 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
// SERVER SETUP
// ====================================
// REQUIRE ALL THE NECESSARY PACKAGES
// ====================================
var express = require('express');
var app = express();
var bodyParser = require('body-parser');
var morgan = require('morgan');
var path = require('path');
var port = process.env.PORT || 8080;
// APPLICATION CONFIGURATION
// ====================================
// use the body-parser to get information from POST requests
app.use(bodyParser.urlencoded({extended: true}));
app.use(bodyParser.json());
// configure app to handle CORS requests (PROBABLY WON'T NEED THIS THO)
app.use(function(req, res, next) {
res.setHeader('Access-Control-Allow-Origin', '*');
res.setHeader('Access-Control-Allow-Methods', 'GET, POST');
res.setHeader('Access-Control-Allow-Headers', 'X-Requested-With,content-type, Authorization');
next();
});
// log all the requests to the console
app.use(morgan('dev'));
// set static files location
// used for requests that our frontend will make
app.use(express.static(__dirname + '/public'));
// API ROUTES
// ====================================
// send user to main page
app.get('*', function(req, res) {
res.sendFile(path.join(__dirname + '/public/app/views/index.html'));
});
// START SERVER
// ====================================
app.listen(port);
console.log('Server started on localhost:' + port);