1.0.1 • Published 11 months ago
sveltekit-proxy v1.0.1
SvelteKit Proxy
This package is for creating proxies in SvelteKit applications. Since the vite proxy is only applicable in development mode based on the docs.
How to
Install
npm install sveltekit-proxy // or yarn add sveltekit-proxy
Import
import { handleProxy } from 'sveltekit-proxy';
Use it
// hooks.server.ts const apiPath = '/api' export const handle: Handle = async ({ event, resolve }) => { if (event.url.pathname.includes(apiPath)) { return handleProxy({ target: "some domain", rewrite: (path) => path.replace(apiPath, ''), origin: "origin" })({ event, resolve }); } return resolve(event); };
Options
Name Description Required Default target
Target proxy URL Yes origin
Set to avoid the abused proxy, only permitted if the origin is valid. Default undefined
which will allow from allNo undefined
rewrite
Rewrite the path
No undefined