From e62eede6b81dc56fac2c1b7e5e086d7671a6e91d Mon Sep 17 00:00:00 2001
From: Moreau Elise <moreau.elise13@gmail.com>
Date: Sat, 19 Jun 2021 13:00:59 +0200
Subject: [PATCH] [cors] package : use express cors to allow access

---
 api/package.json | 1 +
 api/server.js    | 8 ++------
 2 files changed, 3 insertions(+), 6 deletions(-)

diff --git a/api/package.json b/api/package.json
index 2cf3102ec..8455f6364 100644
--- a/api/package.json
+++ b/api/package.json
@@ -3,6 +3,7 @@
   "version": "0.0.0",
   "description": "A simple chat",
   "dependencies": {
+    "cors": "^2.8.5",
     "express": "^4.17.1",
     "express-joi-validation": "^5.0.0",
     "express-jwt": "^6.0.0",
diff --git a/api/server.js b/api/server.js
index 55371211d..296b4123d 100644
--- a/api/server.js
+++ b/api/server.js
@@ -1,4 +1,5 @@
 import express from 'express'
+import cors from 'cors'
 import * as http from 'http'
 import mongoose from "mongoose";
 import WebSocket from 'ws'
@@ -33,12 +34,7 @@ wss.on('connection', function (ws) {
 
 app.use(express.json());
 
-app.use(function(req, res, next) {
-  res.header("Access-Control-Allow-Origin", "*");
-  res.header("Access-Control-Allow-Headers", "*");
-  res.header("Access-Control-Allow-Methods", "POST, GET, PUT, DELETE");
-  next();
-});
+app.use(cors());
 
 app.get('/', function (req, res) {
     // res.send('OK')
-- 
GitLab