Dynamic Route Not Matching Expected URL Patterns /sitemap_*.xml or /sitemap_:id.xml
The current route definition app.get("/sitemap_*", sitemaps) isn't catching requests like /sitemap_823.xml. This happens because the asterisk (*) in the route isn't a proper match for such patterns.
From the docs:
Routes are matched in order of specificity, not by the order you register them:
- Highest priority - static routes, think “/hello/this/is/static”.
- Middle priority - parameter routes, think “/candy/:kind”, where value of :kind is retrieved by req.get_parameter(0).
- Lowest priority - wildcard routes, think “/hello/*”. In other words, the more specific a route is, the earlier it will match. This allows you to define wildcard routes that match a wide range of URLs and then “carve” out more specific behavior from that.
“any” routes, those who match any HTTP method, will match with lower priority than routes which specify their specific HTTP method (such as GET) if and only if the two routes otherwise are equally specific.
Can you give some reproducible example? How are your routes setup?
I use this
app.get("/static/:path", static) app.get("/*", catch_all) app.get("/robots.txt", robots) app.get("/sitemap_*", sitemaps)
I use this
app.get("/static/:path", static) app.get("/*", catch_all) app.get("/robots.txt", robots) app.get("/sitemap_*", sitemaps)
this need to be the last one:
app.get("/*", catch_all)
simple setup
from socketify import App, AppOptions
def make_app(app:App):
app.get("/sitemap_*", lambda res, req: res.end("Hello World socketify from Python!"))
if __name__ == "__main__":
app = App()
make_app(app)
app.listen(3000, lambda config: print("Listening on port http://localhost:%d now\n" % config.port))
app.run()
GET /sitemap_* => Response Hello World socketify from Python!
GET /sitemap_dynamic => Empty Response
Looks like uWS only support exactly matching "*" and not partial like /sitemap_*
https://github.com/uNetworking/uWebSockets/blob/master/src/HttpRouter.h#L185
An workaround would be /:path and manually check if the route starts with "/sitemap_"
Will need some improvements on the HttpRouter to support this.