1.0.1 • Published 11 months ago

sveltekit-proxy v1.0.1

Weekly downloads
-
License
ISC
Repository
github
Last release
11 months ago

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

  1. Install

    npm install sveltekit-proxy
    // or
    yarn add sveltekit-proxy
  2. Import

    import { handleProxy } from 'sveltekit-proxy';
  3. 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);
    };
  4. Options

    NameDescriptionRequiredDefault
    targetTarget proxy URLYes
    originSet to avoid the abused proxy, only permitted if the origin is valid. Default undefined which will allow from allNoundefined
    rewriteRewrite the pathNoundefined
1.0.1

11 months ago

1.0.0

11 months ago