forked from rallyjinx/test-legitometer
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathserver.js
71 lines (56 loc) · 1.97 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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
const express = require('express');
const logger = require('morgan');
const bodyParser = require('body-parser');
const cookieParser = require('cookie-parser');
const cookieSession = require('cookie-session');
const path = require('path');
const cors = require('cors');
require('dotenv').config()
// Set up the express app
const app = express();
app.use(express.static(path.join(__dirname, '/app/public')));
app.get('/', function (req, res) {
const index = path.join(__dirname, 'public', 'index.html');
res.sendFile('./index.html');
});
// Log requests to the console.
app.use(logger('dev'));
// Parse incoming requests data (https://github.com/expressjs/body-parser)
app.use(bodyParser.urlencoded({ extended: false })); //the internet says this should be true
app.use(bodyParser.json());
app.use(cookieParser());
app.use(cookieSession({
secret: "squirrel"
}))
app.use(cors());
app.use(function(req, res, next) {
res.header("Access-Control-Allow-Origin", "*");
res.header('Access-Control-Allow-Methods', 'POST, GET, PUT, OPTIONS')
res.header('Access-Control-Allow-Headers', 'Origin, X-Requested-With, Content-Type, Accept, Authorization')
next();
})
const bookshelf = app.get('./app/db/knex')
app.set('bookshelf', bookshelf);
const missions = require('./app/src/routes/missions');
const casefiles = require('./app/src/routes/casefiles');
const articles = require('./app/src/routes/articles');
const reviews = require('./app/src/routes/reviews');
const users = require('./app/src/routes/users');
// TODO
// app.use('/games', gamesRouter);
// something like that. so in your games router file the route get('/' ...) will actually be at /games/
app.use(missions);
app.use(casefiles);
app.use(articles);
app.use(reviews);
app.use(users);
const port = process.env.PORT || 8888;
app.listen(port, () => {
if (app.get('env') !== 'test') {
console.log('Listening on port', port);
}
});
if (process.env.NODE_ENV === 'production') {
app.use(express.static('app/build'));
}
module.exports = app;