-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathserver.js
48 lines (34 loc) · 1.22 KB
/
server.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
const aws = require('aws-sdk'),
express = require("express"),
port = process.env.PORT || 3000,
mongoose = require("mongoose"),
path = require("path");
//let options = {useMongoClient:true, autoIndex:false, autoReconnect:true, promiseLibrary:global.Promise};
var connectionString = process.env.MONGODB_URI || "mongodb://data/db";
async function main() {
try {
const con = await mongoose.connect(connectionString);
//Initialize models
require("./api/models/appModel");
var app = express();
app.use(express.static("public"));
//Setup default values
var setup = require("./app/appSetup");
setup(app);
//Route importing, calls central router which delegates to granular route files
var central_router = require("./api/routes/centralRoutes"); //importing route
central_router(app); //register the route
//Error Handling
app.use(function (req, res) {
res.status(404).sendFile(path.join(__dirname, "/views/error.html"));
console.log("Cannot find page.");
});
//Start server
app.listen(port, () => {
console.log("Server is listening on port " + port);
});
} catch (error) {
console.log("Error during server opening: " + error);
}
}
main();