Use headers for all routes
This commit is contained in:
@ -10,6 +10,8 @@ const headerKeyPassword = "password";
|
||||
const headerKeyToken = "token";
|
||||
const headerKeyName = "name";
|
||||
const headerKeyMail = "email";
|
||||
const headerKeyVisibility = "visibility";
|
||||
const headerKeyAction = "action";
|
||||
|
||||
function webSocketPath() {
|
||||
const prefix = (window.location.protocol === "https:") ? "wss://" : "ws://"
|
||||
@ -29,29 +31,50 @@ async function performRegisterPlayerRequest(name, password, email) {
|
||||
}
|
||||
|
||||
async function performDeletePlayerRequest(name, password) {
|
||||
return fetch(apiPath + "/player/delete/" + name, { method: 'POST', body: password })
|
||||
return fetch(apiPath + "/player/delete", {
|
||||
method: 'POST',
|
||||
headers: {
|
||||
[headerKeyName]: name,
|
||||
[headerKeyPassword]: password,
|
||||
}
|
||||
})
|
||||
.then(convertServerResponse)
|
||||
.then(function(value) {})
|
||||
}
|
||||
|
||||
async function performLoginPlayerRequest(name, password) {
|
||||
return fetch(apiPath + "/player/login/" + name, { method: 'POST', body: password })
|
||||
return fetch(apiPath + "/player/login", {
|
||||
method: 'POST',
|
||||
headers: {
|
||||
[headerKeyName]: name,
|
||||
[headerKeyPassword]: password,
|
||||
}
|
||||
})
|
||||
.then(convertServerResponse)
|
||||
}
|
||||
|
||||
async function performLogoutRequest(token) {
|
||||
return fetch(apiPath + "/player/logout", { method: 'POST', body: token })
|
||||
return fetch(apiPath + "/player/logout", {
|
||||
method: 'POST',
|
||||
headers: { [headerKeyToken]: token },
|
||||
})
|
||||
.then(convertServerResponse)
|
||||
.then(function(value) {})
|
||||
}
|
||||
|
||||
async function resumeSessionRequest(token) {
|
||||
return fetch(apiPath + "/player/resume", { method: 'POST', body: token })
|
||||
return fetch(apiPath + "/player/resume", {
|
||||
method: 'POST',
|
||||
headers: { [headerKeyToken]: token },
|
||||
})
|
||||
.then(convertServerResponse)
|
||||
}
|
||||
|
||||
async function performGetCurrentTableRequest(token) {
|
||||
return fetch(apiPath + "/player/table", { method: 'POST', body: token })
|
||||
return fetch(apiPath + "/player/table", {
|
||||
method: 'POST',
|
||||
headers: [headerKeyToken]: token,
|
||||
})
|
||||
.then(convertServerResponse)
|
||||
.then(convertJsonResponse)
|
||||
}
|
||||
@ -65,7 +88,7 @@ async function performRecoveryEmailRequest(name) {
|
||||
}
|
||||
|
||||
async function performResetPasswordRequest(token, password) {
|
||||
return fetch(apiPath + "/player/reset", {
|
||||
return fetch(apiPath + "/player/password/new", {
|
||||
method: 'POST',
|
||||
headers: { [headerKeyPassword] : password, [headerKeyToken] : token }
|
||||
})
|
||||
@ -74,36 +97,68 @@ async function performResetPasswordRequest(token, password) {
|
||||
|
||||
async function performCreateTableRequest(token, name, visibility) {
|
||||
const vis = visibility ? "public" : "private";
|
||||
return fetch(apiPath + "/table/create/" + vis + "/" + name, { method: 'POST', body: token })
|
||||
return fetch(apiPath + "/table/create", {
|
||||
method: 'POST',
|
||||
headers: {
|
||||
[headerKeyVisibility]: vis,
|
||||
[headerKeyToken]: token,
|
||||
[headerKeyName]: name,
|
||||
}
|
||||
})
|
||||
.then(convertServerResponse)
|
||||
.then(convertJsonResponse)
|
||||
}
|
||||
|
||||
async function performJoinTableRequest(tableId, token) {
|
||||
return fetch(apiPath + "/table/join/" + tableId, { method: 'POST', body: token })
|
||||
return fetch(apiPath + "/table/join", {
|
||||
method: 'POST',
|
||||
headers: {
|
||||
[headerKeyName]: tableId,
|
||||
[headerKeyToken]: token,
|
||||
}
|
||||
})
|
||||
.then(convertServerResponse)
|
||||
.then(convertJsonResponse)
|
||||
}
|
||||
|
||||
async function performGetPublicTablesRequest(token) {
|
||||
return fetch(apiPath + "/tables/public", { method: 'POST', body: token })
|
||||
return fetch(apiPath + "/tables/public", {
|
||||
method: 'POST',
|
||||
headers: { [headerKeyToken] : token }
|
||||
})
|
||||
.then(convertServerResponse)
|
||||
.then(convertJsonResponse)
|
||||
}
|
||||
|
||||
async function performLeaveTableRequest(token) {
|
||||
return fetch(apiPath + "/table/leave", { method: 'POST', body: token })
|
||||
return fetch(apiPath + "/table/leave", {
|
||||
method: 'POST',
|
||||
headers: { [headerKeyToken] : token },
|
||||
})
|
||||
.then(convertServerResponse)
|
||||
.then(function(value) {})
|
||||
}
|
||||
|
||||
async function performPlayerActionRequest(token, action) {
|
||||
return fetch(apiPath + "/player/action/" + action, { method: 'POST', body: token })
|
||||
return fetch(apiPath + "/player/action", {
|
||||
method: 'POST',
|
||||
headers: {
|
||||
[headerKeyToken] : token,
|
||||
[headerKeyAction] : action,
|
||||
},
|
||||
})
|
||||
.then(convertServerResponse)
|
||||
.then(function(value) {})
|
||||
}
|
||||
|
||||
async function performPlayCardRequest(token, card) {
|
||||
return fetch(apiPath + "/player/card/" + card, { method: 'POST', body: token })
|
||||
return fetch(apiPath + "/player/card", {
|
||||
method: 'POST',
|
||||
headers: {
|
||||
[headerKeyToken] : token,
|
||||
[headerKeyAction] : card,
|
||||
},
|
||||
})
|
||||
.then(convertServerResponse)
|
||||
.then(function(value) {})
|
||||
}
|
||||
|
Reference in New Issue
Block a user