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

[Feature request]get host in route rule #189

Closed
leopku opened this issue May 21, 2024 · 8 comments
Closed

[Feature request]get host in route rule #189

leopku opened this issue May 21, 2024 · 8 comments
Assignees
Labels
enhancement New feature or request

Comments

@leopku
Copy link

leopku commented May 21, 2024

It seems reproxy doesn't support get host in route rule.

For example:

- { route: "^/api/svc1/(.*)", dest: "http:https://s3.my.domain/public/${host}/blah1/$1" }
@umputun
Copy link
Owner

umputun commented May 21, 2024

Not sure I understand the request. I guess this is about the static file provider, and if this is the case, you can already define the host, not as part of the rule itself you provided, but rather as a higher-level "key".

default:
  - {route: "^/api/svc1/(.*)", dest: "http:https://127.0.0.1:8080/blah1/$1"}
  - {route: "/api/svc3/xyz", dest: "http:https://127.0.0.3:8080/blah3/xyz", "ping": "http:https://127.0.0.3:8080/ping"}
  - {route: "/web/", dest: "/var/web", "assets": yes, "keep-host": yes,  "remote": "192.168.1.0/24, 124.0.0.1"}
  - {route: "/web2/", dest: "/var/web2", "spa": yes, "keep-host": no}
srv.example.com:
  - {route: "^/api/svc2/(.*)", dest: "http:https://127.0.0.2:8080/blah2/$1/abc"}

This config defines two sets of rules - one for srv.example.com and another (default) as a catch-all-others

@leopku
Copy link
Author

leopku commented May 22, 2024

Not sure I understand the request. I guess this is about the static file provider.

Yes, in my case that is for serving static files. But as mentioned in the example, the dest was an s3 server for multi-domains.

you can already define the host

in the case of wildcard sub-domain, i don't know the host exactly.

more clearly explain:

there are many sub-folders named by domain name for multi-sites in some bucket of s3. Request should be proxied to different sub-folders.

*.cdn.example.com
  - { route: "^/statics/(.*)", dest: "http:https://s3.my.domain/public/${host}/blah1/$1" }

@leopku
Copy link
Author

leopku commented May 22, 2024

It very useful for both static and dynamic upstreams in wildcard domains case.

@umputun
Copy link
Owner

umputun commented May 22, 2024

Thank you for the clarification, it makes sense. I initially missed the key part with $host from my first look.

umputun added a commit that referenced this issue May 22, 2024
A host substitution functionality has been added to the match logic for the MTProxy match type. This allows for more flexible routing rules, enabling the replacement of "$host" and "${host}" placeholders in the destination URL with the server name, before performing the regex match. Updated corresponding tests to reflect this change.
umputun added a commit that referenced this issue May 22, 2024
A host substitution functionality has been added to the match logic for the MTProxy match type. This allows for more flexible routing rules, enabling the replacement of "$host" and "${host}" placeholders in the destination URL with the server name, before performing the regex match. Updated corresponding tests to reflect this change.
umputun added a commit that referenced this issue May 22, 2024
A host substitution functionality has been added to the match logic for the MTProxy match type. This allows for more flexible routing rules, enabling the replacement of "$host" and "${host}" placeholders in the destination URL with the server name, before performing the regex match. Updated corresponding tests to reflect this change.

make additional test without host substitution

add test with ${host} substitution
umputun added a commit that referenced this issue May 22, 2024
A host substitution functionality has been added to the match logic for the MTProxy match type. This allows for more flexible routing rules, enabling the replacement of "$host" and "${host}" placeholders in the destination URL with the server name, before performing the regex match. Updated corresponding tests to reflect this change.

make additional test without host substitution

add test with ${host} substitution
@umputun
Copy link
Owner

umputun commented May 22, 2024

The change is on the master branch. It supports both $host and ${host} parameters. This functionality was implemented at the low level (discovery.Match) and should work for all providers, including docker, static, and file.

Give it a try and let me know if it works as described.

@umputun umputun self-assigned this May 22, 2024
@umputun umputun added the enhancement New feature or request label May 22, 2024
@leopku
Copy link
Author

leopku commented May 22, 2024

got "Server error"

config

"*.s3.nas.home":
  - {route: "^/(.*)", dest: "http:https://s3.nas.home:9000/www/$host/$1"}

logs:

2024/05/22 13:17:02.420 [WARN]  {discovery/discovery.go:238 discovery.findMatchingMappers} invalid regexp *.s3.nas.home: error parsing regexp: missing argument to repetition operator: `*`
2024/05/22 13:17:02.420 [WARN]  {discovery/discovery.go:238 discovery.findMatchingMappers} invalid regexp *.s3.nas.home: error parsing regexp: missing argument to repetition operator: `*`
2024/05/22 13:17:02.420 [WARN]  {proxy/proxy.go:255 proxy.(*Http).proxyHandler.func2} no match for  /index.html
2024/05/22 13:17:02.451 [WARN]  {discovery/discovery.go:238 discovery.findMatchingMappers} invalid regexp *.s3.nas.home: error parsing regexp: missing argument to repetition operator: `*`
2024/05/22 13:17:02.451 [WARN]  {discovery/discovery.go:238 discovery.findMatchingMappers} invalid regexp *.s3.nas.home: error parsing regexp: missing argument to repetition operator: `*`
2024/05/22 13:17:02.451 [WARN]  {proxy/proxy.go:255 proxy.(*Http).proxyHandler.func2} no match for  /favicon.ico

@umputun
Copy link
Owner

umputun commented May 22, 2024

I doubt it even worked with a wildcard in the server (hostname), and it is likely unrelated to the changes. Probably making it a regular expression will do the trick, i.e., .*.s3.nas.home.

As I have some time, I will add patterns too, but for now they are not supported.

@leopku
Copy link
Author

leopku commented May 22, 2024

as ur words, it works as changing host to .*.s3.nas.home. i will keep this pattern until wildcard pattern supported.

thanks for all ur works.

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