@deckweiss/api-proxy
TypeScript icon, indicating that this package has built-in type declarations

1.0.3 • Public • Published

SvelteKit API-Proxy

This proxy is useful as soon as a man in the middle is required for injecting additional and sensitive information into the request to your backend.

Installation

Step 1: Install package

pnpm i @deckweiss/api-proxy

Step 2: Create hook

// src/hooks.server.ts

import { createApiProxy } from '@deckweiss/api-proxy';

export const handle = createApiProxy({
    apiUrl: 'https://example.com',
    basePath: '/api/v1' // if you requested path starts with this string, then it gets forwarded to {apiUrl}
})

Injecting additional information

Access Token

createApiProxy({
     async middleware(event) {
        const accessToken = (await event.locals.auth())?.accessToken;
        if (accessToken) {
            event.request.headers.set('authorization', `Bearer ${accessToken}`);
        }
    }
})

Prevent forwarding of specific headers

createApiProxy({
     async middleware(event) {
        event.request.headers.delete('cookie')
    }
})

Readme

Keywords

none

Package Sidebar

Install

npm i @deckweiss/api-proxy

Weekly Downloads

1

Version

1.0.3

License

MIT

Unpacked Size

5.41 kB

Total Files

7

Last publish

Collaborators

  • alexanderbetz
  • valentin.schabschneider
  • deckweiss-dev