-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
42 lines (38 loc) · 1.39 KB
/
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
34
35
36
37
38
39
40
41
42
const express = require('express')
const bodyParser = require('body-parser')
const bodyParserErrorHandler = require('express-body-parser-error-handler')
var cors = require('cors');
const app = express()
const dotenv = require("dotenv").config();
const port = process.env.PORT || 4000;
app.use(bodyParser.json())
app.use(bodyParser.json({ limit: '50mb' }));
app.use(bodyParser.urlencoded({ extended: true, limit: '50mb' }));
app.use(bodyParserErrorHandler());
const mongoose = require('mongoose')
const userRouter = require('./routers/userRouter.js')
const chatRouter = require('./routers/chatRoutes.js')
app.use(
cors({origin: ['http://localhost:3000', 'http://127.0.0.1:5000']})
);
app.use('/',userRouter)
app.use('/',chatRouter)
// Serve static assets if in production
if (process.env.NODE_ENV === "production") {
app.use(express.static(path.join(__dirname, "./frontend/build")));
app.get("*", (req, res) =>
res.sendFile(
path.resolve(__dirname, "./frontend", "./build", "./index.html")
)
);
} else {
app.get("/", (req, res) => res.send("Please set to production"));
}
const PORT =process.env.PORT || 5000
LOCAL_ADDRESS='0.0.0.0'
mongoose.connect('mongodb+srv://manichand:[email protected]/chatWithMe?retryWrites=true&w=majority').
then(()=>{
app.listen(port,LOCAL_ADDRESS,()=>{
console.log(`server is running on ${PORT}`)
})
})