Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unable to use path rewrite to external endpoint. #29

Open
FDiskas opened this issue May 13, 2021 · 1 comment
Open

Unable to use path rewrite to external endpoint. #29

FDiskas opened this issue May 13, 2021 · 1 comment
Labels
enhancement New feature or request

Comments

@FDiskas
Copy link

FDiskas commented May 13, 2021

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

@stegano stegano added the enhancement New feature or request label May 16, 2021
@stegano
Copy link
Owner

stegano commented May 16, 2021

Hi @FDiskas

Unfortunately, there are too many features that overlap with httpProxyMiddleware, so I think it would be better to provide guidance on how to use httpProxyMiddleware rather than adding new features anymore. (httpProxyMiddleware provides more features)

As an alternative, try httpProxyMiddleware and the source code below.

import {createProxyMiddleware} from'http-proxy-middleware';

export default createProxyMiddleware({
         timeout: 3000,
         target:'http://localhost:8080',
         router: {
             '/api/demo':'https://google.com',
         },
         pathRewrite: {
             '/api/demo':'',
         },
     });

Thanks 😀

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants