-
Notifications
You must be signed in to change notification settings - Fork 0
/
server.js
37 lines (29 loc) · 961 Bytes
/
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
const express = require('express');
const bodyParser = require('body-parser');
const mongoose = require('mongoose');
const cors = require("cors");
const path = require('path');
const port = process.env.PORT || 5000; // listen to heroku assigned port, or default to 5000
const app = express();
app.use(cors());
app.use(bodyParser.json());
const userRoutes = require('./routes/user-routes');
const itemRoutes = require('./routes/item-routes');
app.use("/api/user", userRoutes)
app.use("/api/item", itemRoutes)
//
app.use(express.static(path.join(__dirname, "frontend", "build")));
app.get('/*', (req, res) => {
res.sendFile(path.join(__dirname, "frontend", "build", "index.html"));
});
mongoose
.connect(
`mongodb+srv://test:testpw@cluster0.4ppgm.mongodb.net/health4u?retryWrites=true&w=majority`
)
.then(() => {
app.listen(port);
console.log(`Connected to MongoDB on port ${port}`);
})
.catch(err => {
console.log(err);
});