-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathindex.js
50 lines (46 loc) · 1.62 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
40
41
42
43
44
45
46
47
48
49
50
//const express = require("express"); // equivalent to import
import express from "express";
import Hello from "./Hello.js";
import Lab5 from "./Lab5/index.js";
import cors from "cors";
import session from "express-session"; // import new server session library
import "dotenv/config"; // import new dotenv library to read .env file
import UserRoutes from "./Kanbas/Users/routes.js";
import CourseRoutes from "./Kanbas/Courses/routes.js";
import ModuleRoutes from "./Kanbas/Modules/routes.js";
import AssignmentRoutes from "./Kanbas/Assignments/routes.js";
const app = express(); // create new express instance
app.use(
cors({
credentials: true, // support cookies
origin: process.env.NETLIFY_URL || "http://localhost:3000", // restrict cross origin resource sharing to the react application
// use different front end URL in dev and in production
})
);
const sessionOptions = {
// default session options
secret: process.env.SESSION_SECRET || "kanbas",
resave: false,
saveUninitialized: false,
};
if (process.env.NODE_ENV !== "development") {
// in production
sessionOptions.proxy = true; // turn on proxy support
sessionOptions.cookie = {
// configure cookies for remote server
sameSite: "none",
secure: true,
domain: process.env.NODE_SERVER_DOMAIN,
};
}
app.use(session(sessionOptions));
// configure server sessions after cors
app.use(express.json()); // do all your work after this line
UserRoutes(app);
CourseRoutes(app);
//EnrollmentRoutes(app);
ModuleRoutes(app);
AssignmentRoutes(app);
Lab5(app);
Hello(app);
app.listen(app.listen(process.env.PORT || 4000)); // listen to http://localhost:4000