-
Notifications
You must be signed in to change notification settings - Fork 4
/
server.js
51 lines (43 loc) · 1.4 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
import express from "express";
import session from "express-session";
// Create an express app instance and define a port for later
const app = express();
const port = 8080;
// Express session middleware automatically manages a session cookie
// that is used to give persistent state between requests, making
// the application stateful and overcoming the stateless nature of HTTP.
app.use(
session({
secret: "secret phrase",
resave: false,
saveUninitialized: false,
cookie: { secure: false },
})
);
// Enable the ejs view engine
app.set("view engine", "ejs");
// Enable support for URL-encoded request bodies (form posts)
app.use(
express.urlencoded({
extended: true,
})
);
// Redirect request to root to the products page
app.get("/", (request, response) => {
response.status(301).redirect("/product_list");
});
// Serve static resources
app.use(express.static("static"));
// Hook up each controller
import productController from "./controllers/products.js";
app.use(productController);
import saleController from "./controllers/sales.js"
app.use(saleController)
import orderController from "./controllers/orders.js";
app.use(orderController);
import staffController from "./controllers/staff.js";
app.use(staffController);
// Start the listening for requests
app.listen(port, () => {
console.log(`Express server started on http://localhost:${port}`);
});