forked from TheAmberlamps/Chow_Line
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathserver.js
56 lines (46 loc) · 1.78 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
47
48
49
50
51
52
53
54
55
56
var express = require("express");
var hbs = require("handlebars");
var exphbs = require("express-handlebars");
var app = express();
var PORT = process.env.PORT || 8080;
// Serve static content for the app from the "public" directory in the application directory.
app.use(express.static("public"));
// Parse application body as JSON
app.use(express.urlencoded({ extended: true }));
app.use(express.json());
app.engine("handlebars", exphbs({ defaultLayout: "main" }));
hbs.registerHelper("ifCond", function(v1, operator, v2, options) {
switch (operator) {
case "==":
return v1 == v2 ? options.fn(this) : options.inverse(this);
case "===":
return v1 === v2 ? options.fn(this) : options.inverse(this);
case "!=":
return v1 != v2 ? options.fn(this) : options.inverse(this);
case "!==":
return v1 !== v2 ? options.fn(this) : options.inverse(this);
case "<":
return v1 < v2 ? options.fn(this) : options.inverse(this);
case "<=":
return v1 <= v2 ? options.fn(this) : options.inverse(this);
case ">":
return v1 > v2 ? options.fn(this) : options.inverse(this);
case ">=":
return v1 >= v2 ? options.fn(this) : options.inverse(this);
case "&&":
return v1 && v2 ? options.fn(this) : options.inverse(this);
case "||":
return v1 || v2 ? options.fn(this) : options.inverse(this);
default:
return options.inverse(this);
}
});
app.set("view engine", "handlebars");
// Import routes and give the server access to them.
var routes = require("./controllers/grocery_controller.js");
app.use(routes);
// Start our server so that it can begin listening to client requests.
app.listen(PORT, function() {
// Log (server-side) when our server has started
console.log("Server listening on: http://localhost:" + PORT);
});