-
Notifications
You must be signed in to change notification settings - Fork 2
/
app.js
81 lines (61 loc) · 2.22 KB
/
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
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
"use strict";
var express = require('express');
var app = express();
var https = require('https');
var bodyParser = require('body-parser');
var fs = require('fs');
var AWS = require('aws-sdk');
var bcrypt = require('bcryptjs');
var uuid = require('node-uuid');
var auth = require('basic-auth');
var path = require('path');
var secureConfig = require('./secure_config.js');
var port = 443;
if(process.argv[2] !== undefined){
port = process.argv[2];
}
//Setup Aws
AWS.config.region = 'us-west-2';
app.use(bodyParser.json({limit: '5mb'}));
app.use(bodyParser.urlencoded({extended: true, limit: '5mb'}));
app.use(function (req, res, next) {
// Website you wish to allow to connect
res.setHeader('Access-Control-Allow-Origin', '*');
// Request methods you wish to allow
res.setHeader('Access-Control-Allow-Methods', 'GET, POST, OPTIONS, PUT, PATCH, DELETE');
// Request headers you wish to allow
res.setHeader('Access-Control-Allow-Headers', 'X-Requested-With,content-type,Authorization');
// Set to true if you need the website to include cookies in the requests sent
// to the API (e.g. in case you use sessions)
res.setHeader('Access-Control-Allow-Credentials', true);
// Pass to next layer of middleware
next();
});
//Load routes for v1 XCloud
var repo = require('./v1/aws-repo.js')(AWS, bcrypt, uuid);
//var repo = require('./v1/mock-repo.js')();
var services = require('./v1/services.js')(repo);
require('./v1/routes-v1.js')(app, services, auth);
//Catchall for reverse engineering.
app.get("*", function(req, res){
res.sendStatus(404);
});
var options = {};
if(secureConfig.use_ssl){
//Add SSL Info
options.cert = fs.readFileSync(secureConfig.ssl_cert);
options.key = fs.readFileSync(secureConfig.ssl_key) ;
options.ca = [
fs.readFileSync(secureConfig.ssl_intermediate[0]),
fs.readFileSync(secureConfig.ssl_intermediate[1])
];
options.secureProtocol = 'SSLv23_method';
options.secureOptions = 'constants.SSL_OP_NO_SSLv3 | constants.SSL_OP_NO_SSLv2';
}
if(secureConfig.use_ssl){
console.log("Starting secure server :" + port);
https.createServer(options, app).listen(port);
} else {
console.log("Starting server :" + port);
app.listen(port);
}