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

Add pathRewrite to proxy options #177

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

pete-murphy
Copy link

@pete-murphy pete-murphy commented May 12, 2024

Problem

What issue is this causing for Elm Land users?

Fixes #176

Solution

How does this code change address the problem described above?

A user can specify a pathRewrite object in a proxy definition

    "proxy": {
      "/api": {
        "target": "http://localhost:3000",
        "pathRewrite": { "^/api": "" }
      },
    }

to proxy requests from "/api" to "http://localhost:3000".

The behavior is based on the pathRewrite option in http-proxy-middleware where the first matching pattern determines the rewrite: https://github.com/chimurai/http-proxy-middleware/blob/f2a0af329969f8a70b3967a969146758a73d8b0e/src/path-rewriter.ts#L33-L39

Notes

(Can be blank!) Are there any unrelated code changes or other notes you'd like to share regarding this PR?

I tested this locally by running elm-land server with proxy options supported by the existing implementation, and again with the new pathRewrite option, and proxying behaves as expected in both cases. I don't know how to add tests for this 😅 I'd be open to suggestions.

Copy link

netlify bot commented May 12, 2024

Deploy Preview for elm-land canceled.

Name Link
🔨 Latest commit 3eba4fd
🔍 Latest deploy log https://app.netlify.com/sites/elm-land/deploys/664027dc4add1e0008ec21a3

Fixes elm-land#176

The behavior is based on the `pathRewrite` in `http-proxy-middleware`
where the first matching pattern determines the rewrite:
https://github.com/chimurai/http-proxy-middleware/blob/f2a0af329969f8a70b3967a969146758a73d8b0e/src/path-rewriter.ts#L33-L39
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

Allow removing proxy prefix
1 participant