-
Notifications
You must be signed in to change notification settings - Fork 2
/
server.js
42 lines (29 loc) · 963 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
37
38
39
40
41
42
const express = require('express');
const loanRouter = require('./routes/api/loan');
const mongoose = require('mongoose');
const path = require('path')
const app = express();
const dbConnection = require('./config/db')
//DB Connection
dbConnection()
// mongoose.connect('mongodb://localhost/loanCalculator', {
// useNewUrlParser: true,
// useCreateIndex: true
// })
// .then(() => console.log("DB Connected successfully"));
app.use(express.static(path.join(__dirname, 'client/build')));
//MIDDLEWARE
app.use(express.json())
app.get('/', (req, res) => {
res.json({app:"iBudget"})
})
//SERVING ROUTES
app.use('/api/loan', loanRouter)
// Right before your app.listen(), add this:
app.get("*", (req, res) => {
res.sendFile(path.join(__dirname, "client", "build", "index.html"));
});
const PORT = process.env.PORT || 8000;
app.listen(PORT, () => {
console.log(`Server is running on port ${PORT}`)
})