-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.js
46 lines (37 loc) · 1001 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
42
43
44
45
46
const express=require('express');
const keys = require('./config/keys');
const mongoose=require('mongoose')
const {MongoUri} =require("./config/keys")
const port=process.env.port||5000
var cors = require('cors')
const path=require("path")
const app=express()
app.use(cors())
require("./models/user")
require("./models/post")
app.use(express.json())
app.use(require("./routes/auth"))
app.use(require("./routes/post"))
app.use(require("./routes/user"))
mongoose.connect(MongoUri,{
useNewUrlParser:true,
useUnifiedTopology:true,
})
mongoose.connection.on("connected",()=>{
console.log("connected");
})
mongoose.connection.on("error",(err)=>{
console.log(err);
})
app.use(express.static(path.join(__dirname, "./frontend/build")))
app.get("*", (req, res) => {
res.sendFile(
path.join(__dirname, "./frontend/build/index.html"),
function (err) {
res.status(500).send(err)
}
)
})
app.listen(port,()=>{
console.log("server running")
})