In Sveltekit & Vite... How to proxy/hide the folder "api"? Works local but not in Vercel

Viewed 68

I'm using sveltekit, when the customers request:

https://example.com/v1/contacts

I would like to be pointing internally to:

https://example.com/api/v1/contacts

*This way I can have a much better cleaner organization in my code.

This is my vite.config.js:

import { sveltekit } from '@sveltejs/kit/vite';

/** @type {import('vite').UserConfig} */
const config = {
    plugins: [sveltekit()],
    server: {
        port: 3001
        proxy: {
            '/v1': {
                target: 'http://127.0.0.1:3001/',
                secure: false,
                changeOrigin: true,
                rewrite: (path) => {
                    return 'api/' + path;
                }
            }
        }
    },
    preview: {
        port: 3001
    }
};

export default config;

It works in localhost, npm run dev, and in localhost when I do npm run preview, but when I upload it to Vercel, it doesn't work. Any ideas?

0 Answers
Related