ahebrank / frontback

Front-end issue submission for Gitlab and Trello
2 stars 1 forks source link

Feature Request: Multiple search/replace entries #44

Closed wonkeythemonkey closed 5 years ago

wonkeythemonkey commented 5 years ago

The current "dev_url_replace" feature can accept a single search string with multiple replacement values.

Example:

"dev_url_replace": "https://dev-project.pantheonsite.io|http://localhost:9000|http://project.docker:9000"

But it cannot accept multiple search strings. I propose that dev_url_replace be expanded to accept an array of search/replace values if needed:

Proposed:

"dev_url_replace": [
    "https://dev-project.pantheonsite.io|http://localhost:9000|http://project.docker:9000",
    "https://live-project.pantheonsite.io|http://localhost:9000|http://project.docker:9000"
]

For simplicity's sake, I prefer this approach to using Regex.

ahebrank commented 5 years ago

Thanks.

I think I might be able to simplify this a lot (and futureproof when hosts change during development) with a new key, dev_host_replace that will parse the incoming URL and replace the host, whatever it is:

"dev_host_replace": "project.docker:9000"

I guess it could also be:

"dev_host_replace": [
    "project.docker:9000",
    "test-whatever.pantheonsite.io"
]

to replicate the current multi-replace option, although I don't know how useful that is currently.

wonkeythemonkey commented 5 years ago

Your alternate suggestion seems much more useful for the vast majority of use cases. I would vote for the multi-replace option to remain, since I now always use project-name.docker for my local dev, but I know most other devs who might step in on the project won't be doing that. I would normally do:

"dev_host_replace": [
    "project.docker:9000",
    "localhost:9000"
]
ahebrank commented 5 years ago

K. I'll have to work the protocol in there, too -- probably makes the most sense just to have the protocol on the host and let the parser figure out whether it needs to be replaced:

"dev_host_replace": [
    "http://project.docker:9000",
    "http://localhost:9000"
]
wonkeythemonkey commented 5 years ago

Agreed. Maybe just default to the original protocol unless a protocol is specified in the replacement, unless that's more trouble than it's worth and you'd prefer to just require a protocol in the replacement.

ahebrank commented 5 years ago

I had to make this a little more complicated to account for when the path also changes (like Gitlab pages fractal hosting in a subdirectory). Now it's:

  "dev_replace": [
    {
      "host": "http://localhost:9000",
      "path": "/frontback/|/"
    },
    {
      "host": "test-pantheon-site.io",
    },
  ]

(where having it as an array is optional)

host works as discussed above. It's technically optional.

path is also optional and does a find/replace in find|replace format like the old option, but only operates on the path portion of the URL. In the example above, it's trimming /frontback from the beginning of the path.