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;
|
const xsrfToken = jhdata.xsrf_token;
|
||||||
|
|
||||||
export const jhapiRequest = (endpoint, method, data) => {
|
export const jhapiRequest = (endpoint, method, data) => {
|
||||||
let api_url = `${base_url}hub/api`;
|
let api_url = new URL(`${base_url}hub/api` + endpoint, location.origin);
|
||||||
let suffix = "";
|
|
||||||
if (xsrfToken) {
|
if (xsrfToken) {
|
||||||
// add xsrf token to url parameter
|
api_url.searchParams.set("_xsrf", xsrfToken);
|
||||||
var sep = endpoint.indexOf("?") === -1 ? "?" : "&";
|
|
||||||
suffix = sep + "_xsrf=" + xsrfToken;
|
|
||||||
}
|
}
|
||||||
return fetch(api_url + endpoint + suffix, {
|
return fetch(api_url, {
|
||||||
method: method,
|
method: method,
|
||||||
json: true,
|
json: true,
|
||||||
headers: {
|
headers: {
|
||||||
|
@@ -4,7 +4,7 @@ import { jhapiRequest } from "./jhapiUtil";
|
|||||||
const withAPI = withProps(() => ({
|
const withAPI = withProps(() => ({
|
||||||
updateUsers: (options) => {
|
updateUsers: (options) => {
|
||||||
let params = new URLSearchParams();
|
let params = new URLSearchParams();
|
||||||
params["include_stopped_servers"] = "1";
|
params.set("include_stopped_servers", "1");
|
||||||
for (let key in options) {
|
for (let key in options) {
|
||||||
params.set(key, options[key]);
|
params.set(key, options[key]);
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user