-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathapp.js
64 lines (52 loc) · 1.54 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
// Modules
var express = require("express");
var mongoose = require("mongoose");
var bodyParser = require("body-parser");
var logger = require("morgan");
var path = require("path");
var app = express();
// Configuration
var config = require("./app/config/development");
app.use(logger("dev"));
app.use(bodyParser.json());
app.use(bodyParser.urlencoded({ extended: false }));
app.use(bodyParser.raw({ type: "application/zip", limit: '100mb' }));
app.use(express.static(path.join(__dirname, "public")));
// Models
require("./app/models/client");
require("./app/models/asset");
// Security
var security = require("./app/utilities/security");
app.use(function(req, res, next) {
security.verifyHeader(req, res, next);
});
// Routes
var clients = require("./app/routes/clients");
var assets = require("./app/routes/assets");
app.use("/clients", clients);
app.use("/assets", assets);
// Database
connect()
.on("error", console.log)
.on("disconnected", connect);
function connect () {
var mongo_db;
var docker_db = process.env.DB_PORT;
if (docker_db) {
mongo_db = docker_db.replace( 'tcp', 'mongodb' ) + '/rome';
} else {
mongo_db = config.db;
}
var options = { server: { socketOptions: { keepAlive: 1 } } };
return mongoose.connect(mongo_db, options).connection;
}
// Seed
var seed = require("./app/utilities/seed");
seed.client();
var port = process.env.PORT || "3000";
app.set("port", port);
app.listen(port);
// Setup HTTP Server
var http = require("http");
var server = http.createServer(app);
console.log("Server Started on port: " + port);