-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathserver.js
45 lines (36 loc) · 1.27 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
const express = require('express')
const app = express()
const connection = require("./middlewares/mongo-connection.js");
const helmet = require('helmet');
const bodyParser = require('body-parser');
const routes = require("./controllers/routes.js");
const data = require("./controllers/data.js");
const DIST_FOLDER = process.cwd() + '/dist';
// app.engine('html', ngExpressEngine({
// bootstrap: AppServerModuleNgFactory,
// providers: [
// provideModuleMap(LAZY_MODULE_MAP)
// ]
// }));
// Start MongoDB connection
connection.connect()
.then((response) => {
// console.log("I'm booted and connected. Moving on...");
})
.catch((data) => {
console.log("Cannot conntect to db. Exiting program: " + data);
process.exit(1);
});
// Use Helmet for security
app.use(helmet());
//
app.use(bodyParser.json()); // support json encoded bodies
app.use(bodyParser.urlencoded({ extended: true })); // support encoded bodies
// Static files
app.use(express.static(DIST_FOLDER))
// Routes for getting and posting data in the site
app.use('/data', data)
// Main router -- ****OTHER ROUTERS NEED TO BE ABOVE THIS LINE!!!!******
app.use("/", routes);
const port = process.env.PORT? process.env.PORT : 3000
app.listen(port, () => console.log('Portfolio 2.0 up and running on port ' + port))