-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathserver.js
45 lines (39 loc) · 1.23 KB
/
server.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
const express = require("express");
const app = express();
const path = require("path");
var cors = require("cors");
var bodyParser = require("body-parser");
const PORT = process.env.PORT;
app.use(express.json());
app.use(cors());
app.use(bodyParser.urlencoded({ extended: "false" }));
app.use(express.static(path.resolve(__dirname, "frontend/build")));
module.exports = function (collection) {
// app.get("/", (req, res) => {
// console.log("hello /link");
// });
app.get("/getData", (req, res) => {
require("./getData")(req, res, collection);
});
app.post("/postData", async (req, res) => {
await collection.insertOne(req.body);
res.status(200).send("real data inserted");
});
app.get("/getHistory", (req, res) => {
require("./getHistory")(req, res, collection);
});
if (process.env.NODE_ENV === "production") {
app.use(express.static("frontend/build/"));
app.get("*", (req, res) => {
console.log(__dirname);
res.sendFile(path.resolve(__dirname, "frontend", "build", "index.html"));
});
} else {
app.get("/", (req, res) => {
res.send("RIT Hall Booking Server running");
});
}
app.listen(PORT, () => {
console.log("Server is listening to port " + PORT);
});
};