-
Notifications
You must be signed in to change notification settings - Fork 0
/
server.js
46 lines (38 loc) · 1.09 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
46
/* eslint-disable no-undef */
const express = require("express");
const mongoose = require("mongoose");
const path = require("path");
require("dotenv").config();
//express app
const app = express();
const PORT = process.env.PORT || 3030;
const jobRoutes = require("./routes/jobs");
const userRoutes = require("./routes/user");
const healthCheckRoutes = require("./routes/healthcheck");
//middleware
app.use(express.json());
app.use((req, res, next) => {
console.log(req.path, req.method);
next();
});
app.use(express.static(path.resolve(__dirname, "./client/build")));
app.use("/api/jobs", jobRoutes);
app.use("/api/user", userRoutes);
app.use("/api/healthcheck", healthCheckRoutes);
//connect to db
mongoose
.connect(process.env.MONG_URI)
.then(() => {
// listen for requests
app.get("*", function (request, response) {
response.sendFile(
path.resolve(__dirname, "./client/build", "index.html")
);
});
app.listen(PORT, () => {
console.log("connected to db and listening on port", process.env.PORT);
});
})
.catch((err) => {
console.log(err);
});