-
Notifications
You must be signed in to change notification settings - Fork 0
/
server.js
36 lines (26 loc) · 1.04 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
const express = require("express")
const app = express()
app.use(express.json())
// const path = require("path");
const dbConnect = require("./dbConnect")
const userRoute = require('./routes/userRoute')
const transactionRoute = require('./routes/transactionRoute')
app.use('/api/users', userRoute);
app.use('/api/transactions/',transactionRoute);
const port = process.env.PORT || 5000;
// if(process.env.NODE_ENV === "production"){
// app.use('/', express.static('client/build')); //frontend fetching
// app.get('*', (req,res) => {
// res.sendFile(path.resolve(__dirname, 'client/build/index.html')); //backend fetching
// })
// }
// step 3: Heroku
if ( process.env.NODE_ENV == "production"){
app.use(express.static("client/build"));
const path = require("path");
app.get("*", (req, res) => {
res.sendFile(path.resolve(__dirname, 'client', 'build', 'index.html'));
})
}
app.get('/', (req,res) => res.send('hello world'));
app.listen(port, () => console.log(`App listening at port ${port}`));