-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
33 lines (28 loc) · 884 Bytes
/
index.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 path = require("path");
const express = require('express')
var cors = require('cors')
const connectToMongo = require('./db')
require('dotenv').config();
const app = express()
app.use(express.static(path.resolve(__dirname, "./client/build")));
app.use(cors())
let port = process.env.PORT || 8000;
app.use(express.json())
//available routes
app.get('/',function (req,res){res.send("checking backend")})
app.use('/api/auth', require('./Routes/auth'))
app.use('/api/notes', require('./Routes/notes'))
app.use(express.static(path.join(__dirname, "./client/build")));
app.get("*", function (_, res) {
res.sendFile(
path.join(__dirname, "./client/build/index.html"),
function (err) {
res.status(500).send(err);
}
);
});
connectToMongo().then(()=>{
app.listen(port, () => {
console.log(`http://localhost:${port}/`)
})
})