-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathserver.js
47 lines (37 loc) · 1.15 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
// Get dependencies
const express = require('express');
const path = require('path');
const http = require('http');
const bodyParser = require('body-parser');
const probables = require('mlbprobablepitchers');
const app = express();
var fs = require('fs');
// file is included here:
eval(fs.readFileSync('utility.js').toString());
// Parsers for POST data
app.use(express.static(__dirname + '/src'));
app.use(bodyParser.json());
app.use(bodyParser.urlencoded({ extended: false }));
/**
* Get port from environment and store in Express.
*/
const port = process.env.PORT || '3000';
app.set('port', port);
app.get('/matchups', function (req, res) {
const todayDate = getDateTime();
probables.get(todayDate, (err, matchups) => {
console.log(matchups)
res.json(matchups)
});
})
app.get('*', function(req, res) {
res.sendFile('./src/index.html', {root: __dirname}); // load the single view file (angular will handle the page changes on the front-end)
});
/**
* Create HTTP server.
*/
const server = http.createServer(app);
/**
* Listen on provided port, on all network interfaces.
*/
server.listen(port, () => console.log(`API running on localhost:${port}`));