Skip to content

Proxy on '/' as exact path, not '/*' #767

Answered by bleszerd
bleszerd asked this question in Q&A
Discussion options

You must be logged in to vote

just updating if they find this question: you can use ^/user$ as exact path and ^/user/**$ to match all routes that have /user as prefix.

You might want to do something like:

[Typescript]

const createRoute = ({
  redirectHost,
  route,
  useAsPrefix = true,
}: IRouteOptions) => {
  const routePath = useAsPrefix ? `${route}/**` : route;

  router.use(
    `^/oldApi/${routePath}$`,
    createProxyMiddleware({
      pathRewrite: {
        '^/oldApi': '/newApi',
      },
      target: redirectHost,
    }),
  );
};

@chimurai thanks for the help

Replies: 2 comments 2 replies

Comment options

You must be logged in to vote
2 replies
@bleszerd
Comment options

@chimurai
Comment options

Comment options

You must be logged in to vote
0 replies
Answer selected by bleszerd
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants