-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathserver.js
49 lines (33 loc) · 1.12 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
44
45
46
47
48
const express = require('express');
const cors = require('cors')
const path = require('path')
const http = require('http');
const {Server}= require('socket.io');
const mongoose = require('mongoose');
const postRoutes = require('./routes/post');
const authRoutes = require('./routes/auth');
//connexion à mongoDB
mongoose.connect('mongodb+srv://Nomena:[email protected]/?retryWrites=true&w=majority',
{
useNewUrlParser: true,
useUnifiedTopology: true })
.then(()=> console.log('connexion à MongoDB reussie'))
.catch(() => console.log('Connexion à MongoDB echoué'));
//server config
const app = express();
const server = http.createServer(app);
const io = new Server(server);
//middleware
app.use(express.json())
//cross origin config
app.use(cors({
origin:"http://localhost:3000",
credential:true
}))
//routes
app.use('/api/post', postRoutes)
app.use('/api/auth', authRoutes)
// app.use('/Uploads', express.static(path.join(__dirname, 'images')))
app.listen(process.env.PORT||3002, () =>{
console.log('app listening on port 3002')
})