Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

How to proxy on Svelte-kit in dev mode

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).

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

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

>Solution :

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',
                },
            },
        },
    },
};
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading