This repository was archived by the owner on Jan 6, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathserver.js
More file actions
99 lines (68 loc) · 3.37 KB
/
server.js
File metadata and controls
99 lines (68 loc) · 3.37 KB
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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
/****************************************************************************
****************************************************************************
Initialize
*****************************************************************************
*****************************************************************************/
// Import packages
const express = require("express");
const exphbs = require("express-handlebars");
const path = require("path");
const methodOverride = require("method-override");
const bodyParser = require("body-parser");
const cookieParser = require("cookie-parser");
// const aws = require("aws-sdk"); //added by John for S3 functions
// Use express
const app = express();
const PORT = process.env.PORT || 3000;
/****************************************************************************
****************************************************************************
Set models
*****************************************************************************
*****************************************************************************/
// Import our models
const maiDB = require(path.join(__dirname, "models"));
/****************************************************************************
****************************************************************************
Set views
*****************************************************************************
*****************************************************************************/
// Set public directory
const directory_public = path.join(__dirname, "public");
app.use(express.static(directory_public));
// Set up Express to handle parsing data
app.use(bodyParser.json());
app.use(bodyParser.text());
// Set extended to true so that we can parse arrays of input fields (e.g. name="captions[0]")
app.use(bodyParser.urlencoded({"extended": true}));
// Set handlebars
app.engine(".hbs", exphbs({
"defaultLayout": "main",
"extname" : ".hbs"
}));
app.set("view engine", ".hbs");
// Set ejs for S3 functions to run. Maybe unnecessary.
// app.engine("html", require("ejs").renderFile); /* added by John per S3 tutorial, maybe unnecessary */
// Set cookie
app.use(cookieParser());
/****************************************************************************
****************************************************************************
Set controllers
*****************************************************************************
*****************************************************************************/
// Override POST methods to handle PATCH and DELETE
app.use(methodOverride("_method"));
// Set routers
const router_html = require(path.join(__dirname, "controllers", "html_routes.js"));
const router_api = require(path.join(__dirname, "controllers", "api_routes.js"));
// Talk to routers
app.use("/", router_html);
app.use("/api", router_api);
/****************************************************************************
****************************************************************************
Listen for connections on the port
*****************************************************************************
*****************************************************************************/
// Uncomment force to reset the database
maiDB.sequelize.sync(/*{"force": true}*/).then(function() {
app.listen(PORT, () => console.log(`App listening on ${PORT}.`));
});