-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
61 lines (50 loc) · 1.41 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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
const express = require('express');
const http = require('http');
const mongoose = require('mongoose');
const cors = require('cors');
const { Server } = require('socket.io');
require('dotenv').config();
const app = express();
app.use(express.urlencoded({ extended: true }));
app.use(express.json());
//몽고디비 연결
mongoose
.connect(process.env.MONGO_URL, {
useNewUrlParser: true,
})
.then(() => console.log('Connected to mongodb'))
.catch(() => console.log('mongodb connection failed'));
//CORS
const corsOptions = {
origin:
process.env.NODE_ENV === 'production'
? 'http://kurlymoly.com'
: 'http://localhost:3000',
credentials: true,
};
app.use(cors(corsOptions));
//ROUTES
const featureRoute = require('./routes/feature');
const itemRoute = require('./routes/item');
const akinatorRoute = require('./routes/akinator');
app.use('/features', featureRoute);
app.use('/items', itemRoute);
app.use('/akinator', akinatorRoute);
//socket
const server = http.createServer(app);
const io = new Server(server, {
cors: {
origin:
process.env.NODE_ENV === 'production'
? 'http://kurlymoly.com'
: 'http://localhost:3000',
methods: ['GET'],
credentials: true,
},
});
const searchingSocket = require('./socket/searchingSocket');
searchingSocket(io);
//LISTENING
server.listen(process.env.PORT, () => {
console.log(`Server listening on port ${process.env.PORT}`);
});