-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathserver.js
31 lines (25 loc) · 944 Bytes
/
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
const express = require("express");
const bodyParser = require("body-parser");
const cors = require("cors");
const apiRouter = require("./apiRouter").router;
const server = express();
const mongoose = require("mongoose");
mongoose.set('useCreateIndex', true);
const MongoClient = require('mongodb').MongoClient;
//const fileUpload = require('express-fileupload');
//Middleware
server.use(bodyParser.urlencoded({ extended: true }));
server.use(bodyParser.json());
server.use(cors());
//server.use(fileUpload());
const port = process.env.PORT || 5001;
server.use((req, res, next) => {
res.setHeader('Acces-Control-Allow-Origin', '*');
res.setHeader('Acces-Control-Allow-Methods', 'GET,POST,PUT,PATCH,DELETE');
res.setHeader('Acces-Contorl-Allow-Methods', 'Content-Type', 'Authorization');
next();
})
server.use("/api/", apiRouter);
server.listen(port, () => {
console.log(`[OK] Serveur lancé dans le port ${port}`);
});