-
Notifications
You must be signed in to change notification settings - Fork 0
/
server.js
45 lines (39 loc) · 1.32 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 bodyParser = require("body-parser");
const path = require("path");
const userRouter = require("./routes/user-router");
const jobRouter = require("./routes/job-router");
const kaggleRouter = require("./routes/kaggle-router");
const app = express();
let cors = require("cors");
const port = process.env.PORT || 5000;
const fileUpload = require("express-fileupload");
const dotenv = require("dotenv");
dotenv.config();
const uri = process.env.MONGOURI;
const mongoose = require("mongoose");
mongoose.connect(uri, { useNewUrlParser: true }).catch((e) => {
console.error("Connection error", e.message);
});
// eslint-disable-next-line no-unused-vars
const db = mongoose.connection;
app.use(
fileUpload({
createParentPath: true,
})
);
app.use(cors());
app.use(bodyParser.json());
app.use(bodyParser.urlencoded({ extended: true }));
app.use("/api", userRouter);
app.use("/api", jobRouter);
app.use("/api", kaggleRouter);
if (process.env.NODE_ENV === "production") {
// Serve any static files
app.use(express.static(path.join(__dirname, "client/build")));
// Handle React routing, return all requests to React app
app.get("*", function (req, res) {
res.sendFile(path.join(__dirname, "client/build", "index.html"));
});
}
app.listen(port, () => console.log(`Listening on port ${port}`));