Commit 2a9f572e authored by Dennis Willers's avatar Dennis Willers 🏀

Set Header 4 Cors

parent dd4bf68c
Pipeline #324 passed with stages
in 3 minutes
const express = require('express');
const io = require("socket.io-client");
//const socket = io('ws://tabu-server.willers.digital');
const socket = io('ws://localhost:80');
const socket = io('ws://tabu-server.willers.digital');
//const socket = io('ws://localhost:80');
function createRouter(db) {
const router = express.Router();
......@@ -15,7 +15,7 @@ function createRouter(db) {
});
const isTrue = function(req, res) {
res.status(200).json({status: 'true'});
res.header('Access-Control-Allow-Origin', "*").status(200).json({status: 'true'});
};
const isSession = function isSession(req, res, next) {
......@@ -28,18 +28,18 @@ function createRouter(db) {
(error, results) => {
if (error) {
console.log(error);
return res.status(500).json({status: 'error'});
return res.header('Access-Control-Allow-Origin', "*").status(500).json({status: 'error'});
} else {
if (results.length > 0) {
next();
} else {
return res.status(200).json({status: 'false'});
return res.header('Access-Control-Allow-Origin', "*").status(200).json({status: 'false'});
}
}
}
);
} else {
return res.status(500).json({status: 'error'});
return res.header('Access-Control-Allow-Origin', "*").status(500).json({status: 'error'});
}
};
......@@ -53,9 +53,9 @@ function createRouter(db) {
(error, results) => {
if (error) {
console.log(error);
res.status(500).json({status: 'false'});
res.header('Access-Control-Allow-Origin', "*").status(500).json({status: 'false'});
} else {
res.status(200).json(
res.header('Access-Control-Allow-Origin', "*").status(200).json(
{
status: 'true',
sessionID: results[0].SessionID,
......@@ -70,7 +70,7 @@ function createRouter(db) {
}
);
} else {
res.status(500).json({status: 'error'});
res.header('Access-Control-Allow-Origin', "*").status(500).json({status: 'error'});
}
};
......@@ -84,7 +84,7 @@ function createRouter(db) {
error => {
if (error) {
console.error(error);
res.status(500).json({status: 'false'});
res.header('Access-Control-Allow-Origin', "*").status(500).json({status: 'false'});
} else {
//Init new Gamestatus
var redTurn = Math.random();
......@@ -96,9 +96,9 @@ function createRouter(db) {
error => {
if (error) {
console.error(error);
res.status(500).json({status: 'false'});
res.header('Access-Control-Allow-Origin', "*").status(500).json({status: 'false'});
} else {
res.status(200).json({status: 'true'});
res.header('Access-Control-Allow-Origin', "*").status(200).json({status: 'true'});
}
}
);
......@@ -106,7 +106,7 @@ function createRouter(db) {
}
);
} else {
res.status(500).json({status: 'error'});
res.header('Access-Control-Allow-Origin', "*").status(500).json({status: 'error'});
}
};
......@@ -118,9 +118,9 @@ function createRouter(db) {
(error, results) => {
if (error) {
console.log(error);
res.status(500).json({status: 'error'});
res.header('Access-Control-Allow-Origin', "*").status(500).json({status: 'error'});
} else {
res.status(200).json(results);
res.header('Access-Control-Allow-Origin', "*").status(200).json(results);
}
}
);
......@@ -144,7 +144,7 @@ function createRouter(db) {
(error, results) => {
if (error) {
console.log(error);
res.status(500).json({status: 'false'});
res.header('Access-Control-Allow-Origin', "*").status(500).json({status: 'false'});
} else {
if (results.length > 0) {
let random = Math.random() * (results.length-1);
......@@ -156,9 +156,9 @@ function createRouter(db) {
sql,
(error) => {
if (error) {
res.status(500).json({status: 'false'});
res.header('Access-Control-Allow-Origin', "*").status(500).json({status: 'false'});
} else {
res.status(200).json(
res.header('Access-Control-Allow-Origin', "*").status(200).json(
{
status: 'true',
cardID: card.CardID,
......@@ -175,12 +175,12 @@ function createRouter(db) {
}
);
} else {
res.status(500).json({status: 'false'});
res.header('Access-Control-Allow-Origin', "*").status(500).json({status: 'false'});
}
}
});
} else {
res.status(500).json({status: 'error'});
res.header('Access-Control-Allow-Origin', "*").status(500).json({status: 'error'});
}
};
......@@ -194,9 +194,9 @@ function createRouter(db) {
(error) => {
if (error) {
console.log(error);
res.status(500).json({status: 'false'});
res.header('Access-Control-Allow-Origin', "*").status(500).json({status: 'false'});
} else {
res.status(200).json({status: 'true'});
res.header('Access-Control-Allow-Origin', "*").status(200).json({status: 'true'});
socket.emit('newRound', {
sessionName: spielname,
isOpen: true
......@@ -206,7 +206,7 @@ function createRouter(db) {
}
);
} else {
res.status(500).json({status: 'false'});
res.header('Access-Control-Allow-Origin', "*").status(500).json({status: 'false'});
}
};
......@@ -221,18 +221,18 @@ function createRouter(db) {
if (error) {
console.log(error);
return
//res.status(500).json({status: 'false'});
//res.header('Access-Control-Allow-Origin', "*").status(500).json({status: 'false'});
} else {
socket.emit('endRound', {
isOpen: true,
sessionName: spielname,
});
//res.status(200).json({status: 'true'});
//res.header('Access-Control-Allow-Origin', "*").status(200).json({status: 'true'});
}
}
);
} else {
//res.status(500).json({status: 'false'});
//res.header('Access-Control-Allow-Origin', "*").status(500).json({status: 'false'});
}
};
......@@ -246,14 +246,14 @@ function createRouter(db) {
(error) => {
if (error) {
console.log(error);
res.status(500).json({status: 'false'});
res.header('Access-Control-Allow-Origin', "*").status(500).json({status: 'false'});
} else {
res.status(200).json({status: 'true'});
res.header('Access-Control-Allow-Origin', "*").status(200).json({status: 'true'});
}
}
);
} else {
res.status(500).json({status: 'false'});
res.header('Access-Control-Allow-Origin', "*").status(500).json({status: 'false'});
}
};
......@@ -270,9 +270,9 @@ function createRouter(db) {
(error) => {
if (error) {
console.log(error);
res.status(500).json({status: 'false'});
res.header('Access-Control-Allow-Origin', "*").status(500).json({status: 'false'});
} else {
res.status(200).json(
res.header('Access-Control-Allow-Origin', "*").status(200).json(
{
status: 'true',
red: JSON.parse(req.body.red)+1,
......@@ -290,9 +290,9 @@ function createRouter(db) {
(error) => {
if (error) {
console.log(error);
res.status(500).json({status: 'false'});
res.header('Access-Control-Allow-Origin', "*").status(500).json({status: 'false'});
} else {
res.status(200).json(
res.header('Access-Control-Allow-Origin', "*").status(200).json(
{
status: 'true',
red: req.body.red,
......@@ -304,7 +304,7 @@ function createRouter(db) {
);
}
} else {
res.status(500).json({status: 'false'});
res.header('Access-Control-Allow-Origin', "*").status(500).json({status: 'false'});
}
};
......@@ -321,9 +321,9 @@ function createRouter(db) {
(error) => {
if (error) {
console.log(error);
res.status(500).json({status: 'false'});
res.header('Access-Control-Allow-Origin', "*").status(500).json({status: 'false'});
} else {
res.status(200).json(
res.header('Access-Control-Allow-Origin', "*").status(200).json(
{
status: 'true',
red: JSON.parse(req.body.red)-1,
......@@ -341,9 +341,9 @@ function createRouter(db) {
(error) => {
if (error) {
console.log(error);
res.status(500).json({status: 'false'});
res.header('Access-Control-Allow-Origin', "*").status(500).json({status: 'false'});
} else {
res.status(200).json(
res.header('Access-Control-Allow-Origin', "*").status(200).json(
{
status: 'true',
red: req.body.red,
......@@ -355,7 +355,7 @@ function createRouter(db) {
);
}
} else {
res.status(500).json({status: 'false'});
res.header('Access-Control-Allow-Origin', "*").status(500).json({status: 'false'});
}
};
......@@ -369,10 +369,10 @@ function createRouter(db) {
(error, results) => {
if (error) {
console.log(error);
res.status(500).json({status: 'error'});
res.header('Access-Control-Allow-Origin', "*").status(500).json({status: 'error'});
} else {
if (results.length > 0) {
res.status(200).json({
res.header('Access-Control-Allow-Origin', "*").status(200).json({
cardID: results[0].CardID,
solution: results[0].Solution,
tabu1: results[0].Tabu1,
......@@ -382,7 +382,7 @@ function createRouter(db) {
tabu5: results[0].Tabu5
});
} else {
res.status(500).json({status: 'false'});
res.header('Access-Control-Allow-Origin', "*").status(500).json({status: 'false'});
}
}
}
......@@ -426,7 +426,6 @@ function createRouter(db) {
router.post('/getCard', [getCard]);
return router;
}
module.exports = createRouter;
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment