-
Notifications
You must be signed in to change notification settings - Fork 1
/
app.js
32 lines (26 loc) · 1.22 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
const express = require('express');
const bodyParser = require('body-parser');
const path = require('path');
const Thing = require('./models/thing');
//On crée l'application express
const app = express();
const mongoose = require('./service/connect');
app.use((req, res, next) => {
//d'accéder à notre API depuis n'importe quelle origine ( '*' ) ;
res.setHeader('Access-Control-Allow-Origin', '*');
//d'ajouter les headers mentionnés aux requêtes envoyées vers notre API (Origin , X-Requested-With , etc.) ;
res.setHeader('Access-Control-Allow-Headers', 'Origin, X-Requested-With, Content, Accept, Content-Type, Authorization');
//d'envoyer des requêtes avec les méthodes mentionnées ( GET ,POST , etc.).
res.setHeader('Access-Control-Allow-Methods', 'GET, POST, PUT, DELETE, PATCH, OPTIONS');
next();
});
//body-parser analyse le corps de la demande
app.use(bodyParser.json());
app.use('/public/images', express.static(path.join(__dirname, 'public/images')));
const stuffRoutes = require('./routes/stuff');
app.use('/api/stuff', stuffRoutes);
const userRoutes = require('./routes/user');
app.use('/api/auth', userRoutes);
const eleveCtrl = require('./routes/eleve');
app.use('/api/eleve', eleveCtrl);
module.exports = app;