Skip to content

Commit

Permalink
feat(ui): handle proxy configs rewriting paths
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
psychedelicious committed Jan 25, 2024
1 parent e59954f commit fc448d5
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 5 deletions.
2 changes: 1 addition & 1 deletion invokeai/frontend/web/src/app/hooks/useSocketIO.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ export const useSocketIO = () => {
const socketOptions = useMemo(() => {
const options: Partial<ManagerOptions & SocketOptions> = {
timeout: 60000,
path: '/ws/socket.io',
path: `${window.location.pathname}ws/socket.io`,
autoConnect: false, // achtung! removing this breaks the dynamic middleware
forceNew: true,
};
Expand Down
2 changes: 1 addition & 1 deletion invokeai/frontend/web/src/i18n.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ if (import.meta.env.MODE === 'package') {
fallbackLng: 'en',
debug: false,
backend: {
loadPath: '/locales/{{lng}}.json',
loadPath: `${window.location.href.replace(/\/$/, '')}/locales/{{lng}}.json`,
},
interpolation: {
escapeValue: false,
Expand Down
4 changes: 3 additions & 1 deletion invokeai/frontend/web/src/services/api/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,9 @@ const dynamicBaseQuery: BaseQueryFn<
const projectId = $projectId.get();

const rawBaseQuery = fetchBaseQuery({
baseUrl: `${baseUrl ?? ''}/api/v1`,
baseUrl: baseUrl
? `${baseUrl}/api/v1`
: `${window.location.href.replace(/\/$/, '')}/api/v1`,
prepareHeaders: (headers) => {
if (authToken) {
headers.set('Authorization', `Bearer ${authToken}`);
Expand Down
5 changes: 3 additions & 2 deletions invokeai/frontend/web/src/services/api/thunks/schema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,9 @@ export const receivedOpenAPISchema = createAsyncThunk(
'nodes/receivedOpenAPISchema',
async (_, { rejectWithValue }) => {
try {
const url = [window.location.origin, 'openapi.json'].join('/');
const response = await fetch(url);
const response = await fetch(
`${window.location.href.replace(/\/$/, '')}/openapi.json`
);
const openAPISchema = await response.json();

const schemaJSON = JSON.parse(
Expand Down

0 comments on commit fc448d5

Please sign in to comment.