4

I have a node dev server running Sapper on http://localhost:3000, and I want all /api/ requests proxy another local dev server written on python http://localhost:8000/api/

This worked perfectly for pure Svelte:

// webpack.config.js

module.exports.devServer = {
    historyApiFallback: true,
    proxy: {
        '/api/': {
            target: 'http://localhost:8000',
            secure: false,
            changeOrigin: true
        }
    },
};

But does absolutely nothing with Sapper - just get default Sapper's 404 error

I guess it is somehow related with Sapper's routing mechanism, but can not find how to deal with it

1 Answer 1

3

Sapper uses Polka server. Proxy can be configured using http-proxy-middleware

src/server.js

const { createProxyMiddleware } = require('http-proxy-middleware');

polka()
    .use('/api', createProxyMiddleware({ target: 'http://localhost:8000' }))
    // other .use, .listen rules
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.