-
Notifications
You must be signed in to change notification settings - Fork 0
/
server.js
47 lines (36 loc) · 1.51 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
// Solution 2: Customer Relations
// ===========================================
// Step 1: Created a Customer model in ./models/customer.js
// Step 2: Updated the Burger model to have a hasOne(models.Customer) relation
// Step 3: Updated the handlebars to display a customers name if there's a 'Customers' property on the Burger
// Step 4: Updated queries in burgerController for updating a burger to add the CustomerId
// Step 5: Updated findAll query in burger_controller for burgers to "include" the customer
// Step 6: Updated findAll query in burger_controller to order returned burgers by burger_name.
var express = require("express");
var bodyParser = require("body-parser");
var methodOverride = require("method-override");
// bring in the models
var db = require("./models");
var app = express();
// Serve static content for the app from the "public" directory in the application directory.
app.use(express.static(__dirname + "./public"));
// parse application/x-www-form-urlencoded
app.use(bodyParser.urlencoded({
extended: false
}));
// override with POST having ?_method=DELETE
app.use(methodOverride("_method"));
var exphbs = require("express-handlebars");
app.engine("handlebars", exphbs({
defaultLayout: "main"
}));
app.set("view engine", "handlebars");
var routes = require("./controllers/burgers_controller");
app.use("/", routes);
app.use("/update", routes);
app.use("/create", routes);
// listen on port 3000
var port = process.env.PORT || 3000;
db.sequelize.sync().then(function() {
app.listen(port);
});