-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathroutes.js
42 lines (36 loc) · 1.13 KB
/
routes.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
/**
* Main application routes
*/
'use strict';
var path = require('path');
var url = require('url');
var Router = require('express').Router;
var services = require('./js/services');
var setupApi = function(app, cors) {
var api = new Router();
services.getRouters().forEach(function(service) {
api.use('/' + service.name + '/project', service.router);
});
app.use('/v1/service', cors(), api);
app.use('/v1/project/save', require('./js/savejson'));
};
var setupDocs = function(app) {
app.get('/docs/v1/', function(req, res) {
res.sendFile(path.join(__dirname, 'docs', 'index-2.html'));
});
};
module.exports = function(app, cors) {
// to allow cors for set domains use the following..
var whitelist = ['http://example1.com', 'http://example2.com'];
var corsOptions = {
origin: function(origin, callback){
var originIsWhitelisted = whitelist.indexOf(origin) !== -1;
callback(originIsWhitelisted ? null : 'Bad Request', originIsWhitelisted);
}
};
setupDocs(app);
setupApi(app, cors);
app.route('/*').get(function(req, res) {
res.json({ error: "Sorry, this site is not supported" });
});
};