-
Notifications
You must be signed in to change notification settings - Fork 1
/
server.js
44 lines (37 loc) · 1.18 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
/*eslint no-console: ["error", { allow: ["warn", "error", "log"] }] */
'use strict';
// BASE SETUP
// =============================================================================
// call the packages we need
require('dotenv').config({
silent: true
});
const express = require('express');
const path = require('path');
const app = express();
const bodyParser = require('body-parser');
const api = require('./controllers/api');
/* Configure app to use bodyParser()
* this will let us get the data from a POST
*/
app.use(bodyParser.urlencoded({
extended: true
}));
app.use(bodyParser.json());
app.set('superSecret', process.env.SECRET);
// REGISTER OUR ROUTES -------------------------------
app.use((req, res, next) => {
res.header('Access-Control-Allow-Origin', '*');
res.header('Access-Control-Allow-Methods', 'POST');
next();
});
app.use('/', express.static(path.join(__dirname, 'views')));
app.route('/problems/')
.post(api.postData);
// CONFIGURE & START THE SERVER
// =============================================================================
const port = process.env.PORT || 8080;
app.listen(port,
() => console.log('Node.js listening on port ' + port)
);
module.exports = app;