-
Notifications
You must be signed in to change notification settings - Fork 0
/
server.js
43 lines (35 loc) · 1.33 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
34
35
36
37
38
39
40
41
42
43
const express = require('express');
const mongoose = require('mongoose');
const cookieParser = require('cookie-parser');
const path = require('path')
const roomsRoute = require('./routes/rooms')
const boardersRoute = require('./routes/boarders')
const userRoute = require('./routes/user')
const verifyToken = require('./middlewares/VerifyToken');
require('dotenv').config()
const app = express();
app.use(cookieParser());
app.use(express.json());
// ------------------------ ROUTES ------------------------ //
app.use('/api/rooms', verifyToken, roomsRoute);
app.use('/api/boarders', verifyToken, boardersRoute);
app.use('/api/users', userRoute);
// --------------- DATABASE REALTED THINGY ---------------- //
let URI = process.env.DEV_DB_STRING
const PORT = process.env.PORT || 4000
// Serve static assets if in production
if (process.env.NODE_ENV === 'production') {
URI = process.env.PROD_DB_STRING
// Set static folder
app.use(express.static('client/build'));
app.get('*', (req, res) => {
res.sendFile(path.resolve(__dirname, 'client', 'build', 'index.html'));
});
}
try {
mongoose.connect(URI, {useNewUrlParser: true, useUnifiedTopology: true}, () =>
console.log("connected"));
}catch (error) {
console.log("could not connect");
}
app.listen(PORT);