mirror of
https://github.com/jupyterhub/jupyterhub.git
synced 2025-10-09 19:13:03 +00:00
use URL api to construct API url
avoids imperfect logic detecting `?`
This commit is contained in:
@@ -3,14 +3,11 @@ const base_url = jhdata.base_url || "/";
|
||||
const xsrfToken = jhdata.xsrf_token;
|
||||
|
||||
export const jhapiRequest = (endpoint, method, data) => {
|
||||
let api_url = `${base_url}hub/api`;
|
||||
let suffix = "";
|
||||
let api_url = new URL(`${base_url}hub/api` + endpoint, location.origin);
|
||||
if (xsrfToken) {
|
||||
// add xsrf token to url parameter
|
||||
var sep = endpoint.indexOf("?") === -1 ? "?" : "&";
|
||||
suffix = sep + "_xsrf=" + xsrfToken;
|
||||
api_url.searchParams.set("_xsrf", xsrfToken);
|
||||
}
|
||||
return fetch(api_url + endpoint + suffix, {
|
||||
return fetch(api_url, {
|
||||
method: method,
|
||||
json: true,
|
||||
headers: {
|
||||
|
@@ -4,7 +4,7 @@ import { jhapiRequest } from "./jhapiUtil";
|
||||
const withAPI = withProps(() => ({
|
||||
updateUsers: (options) => {
|
||||
let params = new URLSearchParams();
|
||||
params["include_stopped_servers"] = "1";
|
||||
params.set("include_stopped_servers", "1");
|
||||
for (let key in options) {
|
||||
params.set(key, options[key]);
|
||||
}
|
||||
|
Reference in New Issue
Block a user