-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathserver.js
More file actions
48 lines (39 loc) · 1.3 KB
/
Copy pathserver.js
File metadata and controls
48 lines (39 loc) · 1.3 KB
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
'use strict';
//Using express app to launch a server
var express = require('express'),
morgan = require('morgan'),
bodyParser= require('body-parser'),
methodOverride = require('method-override'),
nconf = require('nconf'),
api = require('./lib/api/apiCall'),
path = require('path');
var app = express();
//To insert a config file if any
//nconf.env()
// .file({ file: 'config/development.json' });
app.set('port', process.argv[2]|| 8080);
// Enable CORS
var allowCrossDomain = function(req, res, next) {
'use strict';
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, Authorization, Content-Length');
// intercept OPTIONS method
if ('OPTIONS' === req.method) {
res.send(200);
}
else {
next();
}
};
app.use(allowCrossDomain);
app.use(morgan('dev'));
app.use(bodyParser.urlencoded({extended: true}));
app.use(bodyParser.json());
app.use(methodOverride());
app.use(express.static(path.join(__dirname, 'app')));
app.set('views', __dirname + '/app/views');
app.engine('html', require('ejs').renderFile);
app.get('/feeds', api.feeds);
app.listen(app.get('port'));
console.log('Exchange App listening on port http://localhost:', app.get('port'));