xitrum-framework / xitrum

Async and clustered Scala web framework and HTTP(S) server
http://xitrum-framework.github.io/
MIT License
446 stars 52 forks source link

Url.absUrl returns duplicate Config.baseUrl #669

Closed georgeOsdDev closed 6 years ago

georgeOsdDev commented 6 years ago

Xitrum 3.28.11

When we use Config.reverseProxy.baseUrl, Url.absUrl will return wrong string.

Expected: http://www.localhost.com:8000/my_site/?userId=123 Actual: http://www.localhost.com:8000/my_site/my_site/?userId=123

Reproduce code:

@GET("")
class SiteIndex extends DefaultLayout {
  def execute() {
    println(s"""Config.baseUrl -> ${xitrum.Config.baseUrl}""")                       // Config.baseUrl -> /my_site
    println(s"""absUrl(("userId", "123")) -> ${absUrl(("userId", "123"))}""")   // absUrl(("userId", "123")) -> http://www.localhost.com:8000/my_site/my_site/?userId=123
    respondView()
  }
}

xitrum.log

[INFO] Normal routes:
GET        /      quickstart.action.SiteIndex
[INFO] Error routes:
404  quickstart.action.NotFoundError
500  quickstart.action.ServerError
[INFO] Xitrum routes:
GET  /xitrum/xitrum-3.28.11.js  xitrum.js
GET  /xitrum/metrics/viewer     xitrum.metrics.XitrumMetricsViewer
[INFO] Xitrum SockJS routes:
/xitrum/metrics/channel  xitrum.metrics.XitrumMetricsChannel  websocket: true, cookie_needed: false
[INFO] HTTP server started on port 8000
[INFO] HTTPS server started on port 4430
[INFO] Xitrum 3.28.11 started in development mode
[WARN] *** For security, change secureKey in config/xitrum.conf to your own! ***
Config.baseUrl -> /my_site
absUrl(("userId", "123")) -> http://www.localhost.com:8000/my_site/my_site/?userId=123
[INFO] 127.0.0.1 GET / -> quickstart.action.SiteIndex -> 200, 9 [ms]
ngocdaothanh commented 6 years ago

The 2nd my_site is from the Config.withBaseUrl call at xitrum.routing.Route#url. I'll remove it.

ngocdaothanh commented 6 years ago

I'll remove it.

It's incorrect to remove the 2nd one. Because in that case, for example, the result of url[SiteIndex] will be / (it should be /my_site/).

I'll remove the 1st one.

ngocdaothanh commented 6 years ago

Fixed. I'll release a new version soon.

ngocdaothanh commented 6 years ago

I've released Xitrum 3.28.12.

georgeOsdDev commented 6 years ago

Thanks!πŸ™ πŸ™ πŸ™