Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Tabu-Middleware
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Packages
Packages
Container Registry
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Dennis Willers
Tabu-Middleware
Commits
2a9f572e
Commit
2a9f572e
authored
Dec 31, 2020
by
Dennis Willers
🏀
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Set Header 4 Cors
parent
dd4bf68c
Pipeline
#324
passed with stages
in 3 minutes
Changes
1
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
42 additions
and
43 deletions
+42
-43
events.js
events.js
+42
-43
No files found.
events.js
View file @
2a9f572e
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
;
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment