-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathserver.js
39 lines (32 loc) · 1.02 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
var express = require("express");
var path = require("path");
var logger = require("morgan");
var bodyParser = require("body-parser");
var https = require("https");
var http = require("http");
var app = express();
app.use(logger('dev'));
app.use(bodyParser.json());
app.all('/*', function(req, res, next) {
//set CORS headers
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');
if (req.method == 'OPTIONS') {
res.status(200).end();
} else {
next();
}
});
app.use('/', require('./routes'));
//if no route is matched by now, it must be a 404
app.use(function(req, res, next) {
var err = new Error('Not Found');
err.status = 404;
next(err);
});
http.createServer(app).listen(process.env.PORT || 5000);
//https.createServer(options, app).listen(443);
var server = app.listen(app.get('port'), function() {
console.log('Express server listening on port ' + server.address().port);
});