-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.js
52 lines (35 loc) · 1.03 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
// MAIN APPLICATION MODULE
// initializes express framework, listens for requests on a different port
// depending on local or hosted environment, initializes dbOps
// NPM PACKAGE IMPORTS
const express = require("express");
const bodyParser = require("body-parser");
const ejs = require("ejs");
// local imports
const dbOps = require("./src/dbOps.js");
const router = require("./src/router.js");
// EXPRESS INIT
const app = express();
app.use(bodyParser.urlencoded({extended: true}));
app.use(bodyParser.json());
app.set("view engine", "ejs");
app.use(express.static("public"));
app.use("/", router);
// SERVER: PORT 80 OR HEROKU PORT
const port = process.env.PORT || 80;
app.listen(port, () => {
console.log("Server running.");
});
// DETERMINE URL PATH HEADER AS EITHER HOSTED DOMAIN OR LOCAL
let urlheader = "";
if (port == 80) {
urlheader = "localhost:80/";
} else {
urlheader = "https://jod.dev/";
}
// function to export url header
exports.getUrlHeader = function () {
return urlheader;
}
// MONGODB INIT
dbOps.init(port);