-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathapp.js
28 lines (21 loc) · 979 Bytes
/
app.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
var express = require('express');
var http = require('http');
var morgan = require('morgan');
if (process.env.DEWEY_SERVER_APPINSIGHTS_KEY) {
var appInsights = require("applicationinsights");
appInsights.setup(process.env.DEWEY_SERVER_APPINSIGHTS_KEY).start();
console.log('App Insights started with key = ' + process.env.DEWEY_SERVER_APPINSIGHTS_KEY);
}
var app = express();
var cors = function (req, res, next) {
res.header('Access-Control-Allow-Origin', '*');
res.header('Access-Control-Allow-Methods', 'GET,PUT,POST,DELETE');
res.header('Access-Control-Allow-Headers', 'X-Requested-With, X-Access-Token, X-Revision, Content-Type');
next();
};
app.use(cors);
app.use(morgan(':remote-addr - :remote-user [:date[clf]] ":method :url HTTP/:http-version" :status :res[content-length] ":referrer" ":user-agent" :response-time'))
// routing
require('./source/api')(app);
var port = process.env.port || 3000;
http.createServer(app).listen(port, function() {});