-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathserver.js
More file actions
67 lines (61 loc) · 1.96 KB
/
server.js
File metadata and controls
67 lines (61 loc) · 1.96 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
const express = require("express");
const cors = require("cors");
const fs = require("fs");
var bodyParser = require("body-parser");
const { stressTest } = require("./stressTest"); // Import the stressTest function
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ //
const PORT = process.env.PORT || 6999;
const app = express();
app.use(function (req, res, next) {
// res.header("Access-Control-Allow-Origin", "*");
// res.header("Access-Control-Allow-Headers", "X-Requested-With");
res.setHeader("Access-Control-Allow-Origin", "*");
res.setHeader("Access-Control-Allow-Credentials", "true");
res.setHeader("Access-Control-Max-Age", "1810000");
res.setHeader("Access-Control-Allow-Headers", "content-type");
res.setHeader(
"Access-Control-Allow-Methods",
"PUT, POST, GET, DELETE, PATCH, OPTIONS"
);
next();
});
app.use(bodyParser.json());
app.use(bodyParser.urlencoded({ extended: true }));
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ //
app.listen(PORT, () => {
try {
console.log("Running on :", PORT);
} catch (error) {
// handle the error here
console.error("An error occurred: " + error.message);
}
});
app.get("/", (req, res) => {
try {
res.send("Hellow World");
} catch (error) {
// handle the error here
res.send("An error occurred: " + error.message);
}
});
app.get("/stressTest", (req, res) => {
try {
res.send("Got the code!");
} catch (error) {
// handle the error here
res.send("An error occurred: " + error.message);
}
});
app.post("/stressTest", stressTest); // Use the imported stressTest function as the route handler
app.post("/generateCode", (req, res) => {
try {
res.send("OKAYYYY");
let fileName = req.body.quesID;
let code = req.body.code;
console.log(fileName);
fs.writeFileSync(`CodeGen/${fileName}.cpp`, code);
} catch (error) {
// handle the error here
res.send("An error occurred: " + error.message);
}
});