Archived
1
0
Fork 0
This repository has been archived on 2024-02-17. You can view files and clone it, but cannot push or open issues or pull requests.
SOD/app.js

65 lines
1.8 KiB
JavaScript
Raw Normal View History

2020-06-26 16:59:54 +02:00
let express = require("express");
let path = require("path");
let cookieParser = require("cookie-parser");
let session = require("express-session");
2020-06-26 16:59:54 +02:00
let logger = require("morgan");
let config = require("./config/config.json");
2020-06-26 16:59:54 +02:00
let indexRouter = require("./routes/index");
let registerRouter = require("./routes/register");
let loginRouter = require("./routes/login");
let logoutRouter = require("./routes/logout");
2020-08-16 12:48:43 +02:00
let commandRouter = require("./routes/command");
let ordersRouter = require("./routes/orders");
2020-08-16 13:26:58 +02:00
let sandwichesRouter = require("./routes/sandwiches");
2020-08-17 13:22:52 +02:00
let adminRouter = require("./routes/admin");
2020-06-26 16:59:54 +02:00
let app = express();
let sess = {
secret: config.secret,
cookie: {}
}
if (app.get("env") === "production") {
app.set("trust proxy", 1);
sess.cookie.secure = true;
}
2020-06-26 16:59:54 +02:00
// view engine setup
app.set("views", path.join(__dirname, "views"));
app.set("view engine", "pug");
app.use(logger("dev"));
app.use(express.json());
app.use(express.urlencoded({ extended: false }));
app.use(cookieParser());
app.use(session(sess));
2020-06-26 16:59:54 +02:00
app.use(express.static(path.join(__dirname, "public")));
app.use("/", indexRouter);
app.use("/register", registerRouter);
app.use("/login", loginRouter);
app.use("/logout", logoutRouter);
2020-08-14 20:08:00 +02:00
app.use("/command", commandRouter);
2020-08-16 12:48:43 +02:00
app.use("/orders", ordersRouter);
2020-08-16 13:26:58 +02:00
app.use("/sandwiches", sandwichesRouter);
2020-08-17 13:22:52 +02:00
app.use("/admin", adminRouter);
2020-06-26 16:59:54 +02:00
// catch 404 and forward to error handler
app.use((req, res) => {
res.render("error", {message: "Page not found", "error": {}})
});
// error handler
app.use((err, req, res) => {
// set locals, only providing error in development
res.locals.message = err.message;
res.locals.error = req.app.get("env") === "development" ? err : {};
// render the error page
res.status(err.status || 500);
res.render("error");
});
module.exports = app;