Skip to content

Commit c4b8ed8

Browse files
committed
sanitizeAPIRootURL for both api.ts and PacsApp
1 parent b10fa91 commit c4b8ed8

File tree

2 files changed

+13
-5
lines changed

2 files changed

+13
-5
lines changed

src/api/api.ts

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,14 @@ export const collectionJsonToJson = (theData: any) => {
7878
return typeof theData.collection.total === "undefined" ? ret[0] : ret;
7979
};
8080

81+
export const sanitizeAPIRootURL = (API_ROOT: string) => {
82+
if (API_ROOT.length >= 1 && API_ROOT[API_ROOT.length - 1] === "/") {
83+
return API_ROOT.slice(0, API_ROOT.length - 1);
84+
}
85+
86+
return API_ROOT;
87+
};
88+
8189
const callApi = async <T>(
8290
endpoint: string,
8391
{
@@ -96,10 +104,8 @@ const callApi = async <T>(
96104

97105
const default_api_root = window.location.origin;
98106

99-
let API_ROOT = paramsAPIRoot || CONFIG_API_ROOT || default_api_root;
100-
if (API_ROOT.length >= 1 && API_ROOT[API_ROOT.length - 1] === "/") {
101-
API_ROOT = API_ROOT.slice(0, API_ROOT.length - 1);
102-
}
107+
const theAPIRootURL = paramsAPIRoot || CONFIG_API_ROOT || default_api_root;
108+
const API_ROOT = sanitizeAPIRootURL(theAPIRootURL);
103109

104110
let theEndpoint = endpoint;
105111
if (!theEndpoint.includes(API_ROOT)) {

src/components/Pacs/PacsApp.tsx

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ import {
1515
useReducer,
1616
} from "react-reducer-utils";
1717
import { useLocation, useSearchParams } from "react-router-dom";
18+
import { sanitizeAPIRootURL } from "../../api/api.ts";
1819
import type { Lonk, LonkMessageData } from "../../api/lonk/types.ts";
1920
import type { PACSqueryCore } from "../../api/pfdcm/index.ts";
2021
import * as DoPacs from "../../reducers/pacs";
@@ -203,7 +204,8 @@ export default () => {
203204
.map((each) => each.SeriesInstanceUID)
204205
.join(",");
205206

206-
const url = `${config.API_ROOT}/pacs/sse/?pacs_name=${service}&series_uids=${series_uids}`;
207+
const apiRootURL = sanitizeAPIRootURL(config.API_ROOT);
208+
const url = `${apiRootURL}/pacs/sse/?pacs_name=${service}&series_uids=${series_uids}`;
207209
const eventSource = new EventSource(url);
208210
console.info("PacsApp.eventSource: new eventSource");
209211

0 commit comments

Comments
 (0)