-
Notifications
You must be signed in to change notification settings - Fork 29
/
Copy pathserver.js
41 lines (30 loc) · 1.04 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
const express = require('express');
const bodyParser = require('body-parser');
const passport = require('passport');
const path = require('path');
require('dotenv').config();
require('./bingo-api/models/db');
require('./bingo-api/config/passport');
const routesApi = require('./bingo-api/routes/index');
const app = express();
const allowCrossDomain = function (req, res, next) {
res.header('Access-Control-Allow-Origin', 'http://localhost:8000');
res.header('Access-Control-Allow-Methods', 'GET, PUT, POST, DELETE, OPTIONS');
res.header('Access-Control-Allow-Headers', 'Content-Type, authorization');
next();
};
app.use(allowCrossDomain);
app.use(bodyParser.json());
app.use(bodyParser.urlencoded({ extended: false }));
app.use(passport.initialize());
app.use('/bingo-api', routesApi);
app.use(function(req, res) {
res.sendFile(path.join(__dirname, '/', 'index.html'));
});
app.use(function (err, req, res) {
if (err.name === 'UnauthorizedError') {
res.status(401);
res.json({"message" : err.name + ": " + err.message});
}
});
app.listen(8888);