Skip to content

Commit

Permalink
fix bug in URL generating
Browse files Browse the repository at this point in the history
  • Loading branch information
zyr17 committed Jan 4, 2024
1 parent ec7da2a commit 25f44dd
Showing 1 changed file with 10 additions and 4 deletions.
14 changes: 10 additions & 4 deletions src/http.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,11 @@ function getBaseFunc(getURL, successFunc, checkFunc, failFunc) {
// success: receives a parsed JSON object.
// check: receives a response object, if check passed, return object.
// fail: receives an error object.
if (room_name) getURL += '?room=' + room_name;
fetch(getURL)
let url = new URL(getURL);
if (room_name) {
url.searchParams.append('room', room_name);
}
fetch(url.toString())
.then(response => {
return checkFunc(response);
})
Expand All @@ -22,8 +25,11 @@ function getBaseFunc(getURL, successFunc, checkFunc, failFunc) {
}

function postBaseFunc(postURL, data, successFunc, checkFunc, failFunc) {
if (room_name) postURL += '?room=' + room_name;
fetch(postURL, {
let url = new URL(postURL);
if (room_name) {
url.searchParams.append('room', room_name);
}
fetch(url.toString(), {
method: 'POST',
headers: {
'Content-Type': 'application/json'
Expand Down

0 comments on commit 25f44dd

Please sign in to comment.