Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
seferturan committed Feb 12, 2025
1 parent 4d17b41 commit 61e2978
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 12 deletions.
4 changes: 2 additions & 2 deletions projects/client/src/lib/features/gateway/handle.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@ import type { Handle } from '@sveltejs/kit';
export const handle: Handle = async ({ event, resolve }) => {
const url = new URL(event.request.url);

if (url.pathname.startsWith(ClientEnvironment.svelte)) {
if (url.pathname.startsWith(ClientEnvironment.legacy)) {
const traktUrl = new URL(
url.pathname.replace(ClientEnvironment.svelte, ''),
url.pathname.replace(ClientEnvironment.legacy, ''),
TRAKT_TARGET_ENVIRONMENT,
);

Expand Down
3 changes: 2 additions & 1 deletion projects/client/src/lib/requests/ClientEnvironment.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
export enum ClientEnvironment {
svelte = '/_api/trakt',
legacy = '/_api/trakt',
svelte = '/api/trakt',
test = 'http://localhost',
}
14 changes: 7 additions & 7 deletions projects/client/src/lib/requests/api.ts
Original file line number Diff line number Diff line change
@@ -1,22 +1,22 @@
import { createAuthenticatedFetch } from '$lib/requests/_internal/createAuthenticatedFetch.ts';
import { IS_TEST } from '$lib/utils/env/index.ts';
import { ClientEnvironment } from '$lib/requests/ClientEnvironment.ts';
import { IS_DEV, IS_PREVIEW, IS_TEST } from '$lib/utils/env/index.ts';
import { traktApi, type TraktApiOptions } from '@trakt/api';

export type ApiParams = Omit<TraktApiOptions, 'apiKey' | 'environment'> & {
environment?: HttpsUrl;
};

enum ClientEnvironment {
svelte = '/_api/trakt',
test = 'http://localhost',
}

const ENV = (() => {
if (IS_DEV || IS_PREVIEW) {
return ClientEnvironment.svelte as unknown as HttpsUrl;
}

if (IS_TEST) {
return ClientEnvironment.test as unknown as HttpsUrl;
}

return ClientEnvironment.svelte as unknown as HttpsUrl;
return TRAKT_TARGET_ENVIRONMENT as unknown as HttpsUrl;
})();

export const api = ({
Expand Down
4 changes: 2 additions & 2 deletions projects/client/vite.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,10 +51,10 @@ export default defineConfig(({ mode }) => ({
allow: [MONOREPO_ROOT],
},
proxy: {
'/_api': {
'/api/trakt': {
target: TRAKT_TARGET_ENVIRONMENT,
changeOrigin: true,
rewrite: (path) => path.replace(/^\/_api\/trakt/, ''),
rewrite: (path) => path.replace(/^\/api\/trakt/, ''),
},
},
},
Expand Down

0 comments on commit 61e2978

Please sign in to comment.