Skip to content

Unable to use path rewrite to external endpoint. #29

@FDiskas

Description

@FDiskas

Unable to use path rewrite to external endpoint.
using vanila http-proxy-middleware it is possible using router
https://github.com/chimurai/http-proxy-middleware/blob/c935888ea7135365bea3c4c81e4ffe48f359a670/examples/response-interceptor/index.js#L39

Pseudo code

// src/pages/api/demo.ts
export default (req: NextApiRequest, res: NextApiResponse) =>
    httpProxyMiddleware(req, res, {
        timeout: 3000,
        target: 'http://localhost:8080',
        router: {
            '/api/demo': 'https://google.com',
        },
        pathRewrite: {
            '/api/demo': '',
        },
    }).catch(async (error) => {
        res.end(error.message);
        console.log(error);
    });

As a workaround i create multiple files with different target option

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions