-
Notifications
You must be signed in to change notification settings - Fork 0
/
node.js
47 lines (37 loc) · 1.55 KB
/
node.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
const express = require('express');
const dotenv = require('dotenv').config();
const helmet = require('helmet');
const bodyParser = require('body-parser');
const app = express();
const routes = require("./routes/routes.js");
const connection = require("./routes/mongo-connection.js");
const data = require('./routes/data.js');
// Start MongoDB connection
connection.connect()
.then(function(response){
// console.log("I'm booted and connected. Moving on...");
})
.catch(function(data){
console.log("Cannot conntect to db. Exiting program: " + data);
process.exit(1);
});
// Use Helmet for security
app.use(helmet());
// Make use of the prerenderer for search engines
app.use(require('prerender-node').set('prerenderToken', process.env.PRERENDER_TOKEN));
app.use(bodyParser.json()); // support json encoded bodies
app.use(bodyParser.urlencoded({ extended: true })); // support encoded bodies
// Router for static assets throughout site
app.use("/img", express.static(__dirname + "/assets/img"));
app.use("/js", express.static(__dirname + "/assets/js"));
app.use("/sass", express.static(__dirname + "/assets/sass"));
app.use("/views", express.static(__dirname + "/assets/views"));
app.use("/pages", express.static(__dirname + "/pages"));
app.use("/recaptcha", express.static(__dirname + "/node_modules/angular-recaptcha/release"));
// Data loading routes
app.use("/data", data)
// Main router
app.use("/", routes);
app.set('view engine', 'html');
app.listen(process.env.PORT || 3000);
console.log("App running on port " + (process.env.PORT ? process.env.PORT : 3000));