sveltejs / sapper

The next small thing in web development, powered by Svelte
https://sapper.svelte.dev
MIT License
7k stars 434 forks source link

Proxy in sapper for local API calls #805

Closed thomasmorice-zz closed 5 years ago

thomasmorice-zz commented 5 years ago

Hello, I'm having hard time configuring a proxy for my local dev environment. I'm developing a lambda function (netlify) in parralel of my app (localhost:9000/.netlify/functions/hello) and these functions needs to be proxies in my sapper environment (localhost:3000/.netlify/functions/hello) I see no way of doing it easily through rollup or polka.. I guess this is where it is supposed to sit.. anyone has done it before maybe ?

Many thanks

Conduitry commented 5 years ago

GitHub issues aren't the right place for support questions like this. Please ask on StackOverflow or in our Discord chat room.

swyxio commented 4 years ago

@thomasmorice note that you can use Netlify Dev for netlify stuff https://github.com/netlify/cli/blob/master/docs/netlify-dev.md to do what you needed there

snowman-repos commented 4 years ago

@thomasmorice did you ever figure out how to do this?

benmccann commented 4 years ago

I've used http-proxy-middleware to proxy calls to another server

snowman-repos commented 4 years ago

Do you have an example repo to share? I'm using the rollup template and I've tried http-proxy-middleware and it's still not working

benmccann commented 4 years ago

Here's my server.js:

polka()
    .use('/api', createProxyMiddleware({ target: host, changeOrigin: true }))
    .use(
        compression({ threshold: 0 }),
        sirv('static', { dev }),
        app
    )
    .listen(PORT, err => {
        if (err) console.log('error', err);
    });

I'm not using it for netlify, but to send API calls to another server