feat: rewrite api on dev

This commit is contained in:
EETagent 2022-12-14 18:05:25 +01:00
parent fdf7dc66c5
commit ce4d8ae5ff
2 changed files with 11 additions and 2 deletions

View file

@ -2,7 +2,7 @@ import type { AxiosError } from 'axios';
export type Fetch = (input: RequestInfo, init?: RequestInit) => Promise<Response>;
export const API_URL = 'http://localhost:8000';
export const API_URL = '/api';
export interface ApiError {
error: AxiosError | unknown;

View file

@ -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;