-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapp.js
More file actions
46 lines (37 loc) · 1.21 KB
/
Copy pathapp.js
File metadata and controls
46 lines (37 loc) · 1.21 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
import express from "express";
import passport from "./auth/passport.js";
import "dotenv/config";
const app = express();
import sessionMiddleware from "./auth/sessionMiddleware.js";
import cors from "cors";
import isNotLoggedIn from "./auth/isNotLoggedIn.js";
import indexRouter from "./routes/indexRouter.js";
import statusRouter from "./routes/statusRouter.js";
import isLoggedIn from "./auth/isLoggedIn.js";
import apiRouter from "./routes/apiRouter.js";
app.use(
cors({
credentials: true,
origin: "http://localhost:5173",
}),
);
app.use(express.json());
app.use(express.urlencoded({ extended: true }));
import path from "node:path";
const assetsPath = path.join(import.meta.dirname, "public");
app.use(express.static(assetsPath));
app.use(sessionMiddleware);
app.use(passport.session());
app.use("/status", isLoggedIn, statusRouter);
app.use("/api", apiRouter);
app.use("/", isNotLoggedIn, indexRouter);
app.use((req, res) => {
res.status(404).json("No resource found");
});
// eslint-disable-next-line no-unused-vars
app.use((err, req, res, next) => {
// eslint-disable-next-line no-console
console.error(err);
res.status(500).json(err.message || "Error 500: Internal Server Error");
});
export default app;