-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.js
45 lines (26 loc) · 1.08 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
const express = require('express');
const mongoose = require('mongoose');
const dotenv = require('dotenv');
const userRoutes = require('./routes/user');
app = express();
app.use(express.json());
app.use('/api/auth', userRoutes); // use the api of auth user (signup & login)
dotenv.config();
const PORT = process.env.PORT;
const MONGODB_URL = process.env.MONGODB_URL;
//connect to db
mongoose.connect(MONGODB_URL,
{ useNewUrlParser: true,
useUnifiedTopology: true })
.then(() => console.log(`Connexion à MongoDB réussie ! port: ${PORT}`))
.catch(() => console.log('Connexion à MongoDB échouée !'));
app.get("/", function(req,res, next) {
res.send('ok')
});
app.use((req, res, next) => { // pour la sécurité CORS ; la communication entre differents origins
res.setHeader('Access-Control-Allow-Origin', '*');
res.setHeader('Access-Control-Allow-Headers', 'Origin, X-Requested-With, Content, Accept, Content-Type, Authorization');
res.setHeader('Access-Control-Allow-Methods', 'GET, POST, PUT, DELETE, PATCH, OPTIONS');
next();
});
module.exports = app;