-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
52 lines (35 loc) · 1.25 KB
/
index.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
var express = require('express');
var mongoose = require('mongoose');
var auth = require('./auth/index.js');
var authMiddleware = require('./auth/middleware.js');
var respondTypes = require('./utils/respondTypes.js');
var Players = require('./apis/Players.js');
var TurnBasedMatches = require('./apis/TurnBasedMatches.js');
var Questions = require('./apis/Questions.js');
var Admin = require('./apis/Admin.js');
var app = express();
// Loading Database:
var db = mongoose.connect('mongodb://localhost/pinfever');
var port = 8080;
app.listen(port, function() {
console.log("STARTED pinfever SERVER! PORT: ", port);
});
app.use(function(req, res, next) {
//console.log(req.path, req.headers);
res.header('Access-Control-Allow-Origin', "*"); // TODO - Make this more secure!!
res.header('Access-Control-Allow-Methods', 'GET,PUT,POST');
res.header('Access-Control-Allow-Headers', 'Origin,X-Requested-With,Content-Type,Accept,api-auth-token');
next();
});
app.use(respondTypes());
app.use(authMiddleware());
app.use('/auth', auth());
app.use('/players', Players());
app.use('/turnbasedmatch', TurnBasedMatches());
app.use('/question', Questions());
app.use('/admin', Admin());
app.use(function(req, res, next) {
res.notFoundError({
auth: req.auth
});
});