-
Notifications
You must be signed in to change notification settings - Fork 4
/
app.js
64 lines (57 loc) · 1.85 KB
/
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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
const express = require("express");
const app = express();
const cors = require('cors');
const bodyParser = require("body-parser");
const cookieParser = require("cookie-parser");
const path = require("path");
require("dotenv").config();
/*
* special settings
*/
// websocket
const webSocket = require("./socket");
// mongoDB connection
const mongoose = require("mongoose");
const {MONGO_ID, MONGO_PASSWORD, MONGO_APPNAME, NODE_ENV} = process.env;
const MONGO_URL = `mongodb+srv://${MONGO_ID}:${MONGO_PASSWORD}@${MONGO_APPNAME}-gbvll.mongodb.net/test?retryWrites=true&w=majority`;
const connect = mongoose.connect(MONGO_URL, {
useNewUrlParser: true, useUnifiedTopology: true,
useCreateIndex: true, useFindAndModify: false
})
.then(() => console.log('MongoDB Connected...'))
.catch(err => console.error(err));
// const connect = require("./schemas");
// connect();
/*
* use
*/
app.use(bodyParser.urlencoded({extended: true}));
app.use(bodyParser.json());
app.use(cors())
app.use(cookieParser());
// Serve static files from the React app
app.use(express.static(path.join(__dirname, 'client/build')));
// routing
const indexRouter = require("./routes");
const authRouter = require("./routes/auth");
const usersRouter = require("./routes/users");
const matchRouter = require("./routes/match");
const updatesRouter = require("./routes/updates");
const resetPasswordRouter = require("./routes/reset_password");
app.use('/api', indexRouter)
app.use('/api', authRouter)
app.use('/api', usersRouter)
app.use('/api', matchRouter)
app.use('/api', updatesRouter)
app.use('/api', resetPasswordRouter)
app.get('*', (req, res) => {
res.sendFile(path.join(__dirname + '/client/build/index.html'));
});
/*
* run server and connect with webSocket
*/
const port = process.env.PORT || 5000;
const server = app.listen(port, () => {
console.log(`Listening on port ${port}`)
});
webSocket(server, app);