1.0.1 • Published 1 year 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-proxyImport
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 targetTarget proxy URL Yes originSet to avoid the abused proxy, only permitted if the origin is valid. Default undefinedwhich will allow from allNo undefinedrewriteRewrite the pathNo undefined