How to proxy on Svelte-kit in dev mode

Viewed 664

I am trying to redirect for local development my requests to /api/** to my backend server.

So a request to http://localhost:3000/api/upload goes to http://localhost:8080/api/upload.

I cannot find any svelte.config.js configuration, to get this to work for dev. Also svelte-kit dev does not provide this configuration (or I cannot find it).

Does anyone know how to do so in svelte-kit?

1 Answers

In the Svelte config you can pass options to vite via kit.vite. Proxy rules can be set up via server.proxy, so it should be something like:

const config = {
    // ...
    kit: {
        // ...
        vite: {
            server: {
                proxy: {
                    '/api': 'http://localhost:8080',
                },
            },
        },
    },
};
Related