-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathserver.js
More file actions
78 lines (66 loc) · 1.75 KB
/
server.js
File metadata and controls
78 lines (66 loc) · 1.75 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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
import "dotenv/config";
import path from "path";
import http from "http";
import cors from "cors";
import cookieParser from "cookie-parser";
import express from "express";
import expressWS from "express-ws";
import passport from "passport";
import api_routes from "./routes/api_routes.js";
import config from "./config.js";
import { sleep } from "./utils/promise_utils.js";
import Code_Analyser from "./services/code_analyser.js";
const port = config.port;
const app = express();
const server = http.createServer(app);
expressWS(app, server);
// setup cors
app.use(
cors({
origin: [
process.env.SERVER_URL,
process.env.FRONTEND_DEV_URL,
process.env.FRONTEND_PROD_URL,
],
credentials: true,
})
);
app.use(cookieParser());
app.use(express.json());
app.use(passport.initialize());
// ----- ROUTES -----
// api
app.use("/api/v1", api_routes);
// web app
app.get("*", express.static(path.resolve(process.cwd(), "client", "build")));
app.get("*", async (req, res, next) => {
res.sendFile(path.join(process.cwd(), "client", "build", "index.html"));
});
server.listen(port, () => {
console.log(`Listening on port ${port}`);
});
// import db from "./db/db.js";
(async () => {
// // any startup instructions for the server
// let code_analyser = new Code_Analyser(
// "./testing/linked_list.cpp",
// (event) => {
// console.log(event);
// }
// );
// code_analyser.run();
// code_analyser.input("3");
// console.log(
// await db.users.update_user("bcd@gmail.com", {
// name: "abc",
// email: "abc@gmail.com",
// })
// );
// console.log(
// await db.query("UPDATE users SET name = 'def' WHERE name = 'abc';")
// );
// console.log(
// (await db.query("SELECT * FROM users WHERE username = $1", ["se2422"]))
// .rowCount
// );
})();