From ce4d8ae5ffc98e551642da8b6a61b0c7d76aa65a Mon Sep 17 00:00:00 2001 From: EETagent Date: Wed, 14 Dec 2022 18:05:25 +0100 Subject: [PATCH] feat: rewrite api on dev --- frontend/src/lib/@api/index.ts | 2 +- frontend/vite.config.ts | 11 ++++++++++- 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/frontend/src/lib/@api/index.ts b/frontend/src/lib/@api/index.ts index 9a16f8a..4c91982 100644 --- a/frontend/src/lib/@api/index.ts +++ b/frontend/src/lib/@api/index.ts @@ -2,7 +2,7 @@ import type { AxiosError } from 'axios'; export type Fetch = (input: RequestInfo, init?: RequestInit) => Promise; -export const API_URL = 'http://localhost:8000'; +export const API_URL = '/api'; export interface ApiError { error: AxiosError | unknown; diff --git a/frontend/vite.config.ts b/frontend/vite.config.ts index 1695034..1753371 100644 --- a/frontend/vite.config.ts +++ b/frontend/vite.config.ts @@ -2,7 +2,16 @@ import { sveltekit } from '@sveltejs/kit/vite'; import type { UserConfig } from 'vite'; const config: UserConfig = { - plugins: [sveltekit()] + plugins: [sveltekit()], + server: { + proxy: { + '/api': { + target: 'http://localhost:8000', + changeOrigin: true, + rewrite: (path) => path.replace(/^\/api/, '') + } + } + } }; export default config;