-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.js
41 lines (33 loc) · 952 Bytes
/
app.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
require("dotenv").config();
const express = require("express");
const mongoose = require("mongoose");
const workoutRoutes = require("./routes/workouts");
const userRoutes = require("./routes/user");
const path = require("path");
// express app
const app = express();
app.use(express.static(path.resolve(__dirname, "./client/build")));
// global middleware
app.use(express.json());
app.use((req, res, next) => {
console.log(req.path, req.method);
next();
});
// routes
app.use("/api/workouts", workoutRoutes);
app.use("/api/user", userRoutes);
app.get("*", (req, res) => {
res.sendFile(path.resolve(__dirname, "./client/build", "index.html"));
});
// connect to database
mongoose
.connect(process.env.MONGO_URI)
.then(() => {
// listen for requests
app.listen(process.env.PORT, () => {
console.log("connected to db & listening on port", process.env.PORT);
});
})
.catch((error) => {
console.log(error);
});