-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathindex.js
39 lines (35 loc) · 1.32 KB
/
index.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
const express = require("express");
const fileUpload = require("express-fileupload");
const cookieParser = require("cookie-parser");
const { expressjwt: jwt } = require("express-jwt");
const config = require("./config.json");
const adminRoutes = require("./routes/adminRoutes");
const studentRoutes = require("./routes/studentRoutes");
const departmentRoutes = require("./routes/departmentRoutes");
const cors = require("cors");
const jwkToPem = require("jwk-to-pem");
require("dotenv").config();
const PORT = process.env.PORT || 5000;
const app = express();
app.use(cors({ origin: "http://localhost:5173", credentials: true }));
app.locals.pems = [];
fetch(
"https://#.microsoftonline.com/a57f7d92-038e-4d4c-8265-7cd2beb33b34/discovery/v2.0/keys"
)
.then((response) => response.json())
.then((jwks) => jwks.keys)
.then((keys) => {
app.locals.keys = keys;
keys.forEach((jwk) => app.locals.pems.push(jwkToPem(jwk)));
});
app.use(fileUpload({ useTempFiles: true, tempFileDir: "/tmp/" }));
app.use(express.json());
app.use(express.urlencoded({ extended: true }));
app.use(cookieParser());
app.use("/admin", adminRoutes);
app.use("/student", studentRoutes);
app.use("/department", departmentRoutes);
app.listen(PORT, () => {
console.log(`[+] Server listening on PORT: ${PORT}`);
});
/* vi: set et sw=4: */