-
Notifications
You must be signed in to change notification settings - Fork 0
/
server.js
46 lines (36 loc) · 1.2 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
var express = require('express');
var mongoose = require('mongoose');
var bodyParser = require('body-parser');
var logger = require('morgan');
// var passport = require('passport');
var apiVersion = 1;
var mongoDB = process.env.MONGOLAB_URI || 'mongodb://localhost:27017/twitchbot';
mongoose.connect(mongoDB);
var app = express();
// Body Parser
app.use(bodyParser.json());
app.use(bodyParser.urlencoded({ extended: false }));
// Logging
app.use(logger('dev'));
// CORS
var allowCrossDomain = function(req, res, next) {
res.header('Access-Control-Allow-Origin', '*');
res.header('Access-Control-Allow-Methods', 'GET,PUT,POST,DELETE,OPTIONS');
res.header('Access-Control-Allow-Headers', 'Content-Type, Accept, Authorization, Content-Length, X-Requested-With');
// intercept OPTIONS method
if ('OPTIONS' == req.method) {
res.sendStatus(200);
}
else {
next();
}
};
app.use(allowCrossDomain);
var api = require('./app/routes/api');
app.use('/api/v'+apiVersion, api);
app.use('/assets', express.static(__dirname + '/client/assets'));
app.use(function(req, res, next) {
res.sendFile(__dirname + '/client/index.html');
});
var port = process.env.PORT || 3000;
app.listen(port);