Skip to content

Commit fc448d5

Browse files
feat(ui): handle proxy configs rewriting paths
We can't assume that the base URL is `host:port/` - it could be `host:port/some/path/`. Make the path handling dynamic to account for this.
1 parent e59954f commit fc448d5

File tree

4 files changed

+8
-5
lines changed

4 files changed

+8
-5
lines changed

invokeai/frontend/web/src/app/hooks/useSocketIO.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ export const useSocketIO = () => {
4545
const socketOptions = useMemo(() => {
4646
const options: Partial<ManagerOptions & SocketOptions> = {
4747
timeout: 60000,
48-
path: '/ws/socket.io',
48+
path: `${window.location.pathname}ws/socket.io`,
4949
autoConnect: false, // achtung! removing this breaks the dynamic middleware
5050
forceNew: true,
5151
};

invokeai/frontend/web/src/i18n.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ if (import.meta.env.MODE === 'package') {
3232
fallbackLng: 'en',
3333
debug: false,
3434
backend: {
35-
loadPath: '/locales/{{lng}}.json',
35+
loadPath: `${window.location.href.replace(/\/$/, '')}/locales/{{lng}}.json`,
3636
},
3737
interpolation: {
3838
escapeValue: false,

invokeai/frontend/web/src/services/api/index.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,9 @@ const dynamicBaseQuery: BaseQueryFn<
5757
const projectId = $projectId.get();
5858

5959
const rawBaseQuery = fetchBaseQuery({
60-
baseUrl: `${baseUrl ?? ''}/api/v1`,
60+
baseUrl: baseUrl
61+
? `${baseUrl}/api/v1`
62+
: `${window.location.href.replace(/\/$/, '')}/api/v1`,
6163
prepareHeaders: (headers) => {
6264
if (authToken) {
6365
headers.set('Authorization', `Bearer ${authToken}`);

invokeai/frontend/web/src/services/api/thunks/schema.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,9 @@ export const receivedOpenAPISchema = createAsyncThunk(
2626
'nodes/receivedOpenAPISchema',
2727
async (_, { rejectWithValue }) => {
2828
try {
29-
const url = [window.location.origin, 'openapi.json'].join('/');
30-
const response = await fetch(url);
29+
const response = await fetch(
30+
`${window.location.href.replace(/\/$/, '')}/openapi.json`
31+
);
3132
const openAPISchema = await response.json();
3233

3334
const schemaJSON = JSON.parse(

0 commit comments

Comments
 (0)