How do I configure Undertow handlers to support proper rewriting for SPA bookmarking?

依然范特西╮ 提交于 2019-12-08 02:01:48

问题


I am trying to configure JBoss EAP 7 (via Undertow) to properly rewrite any SPA URLS back to the SPA's index.html using Undertow handlers. Unfortunately, my API is located at /api, so I need to let any requests pass through which start with /api.

Here is my current configuration (lifted from another SO answer):

not equals(%R, '/my-app') and 
not equals(%R, '/my-app/') and 
not equals(%R, '/my-app/index.html') and 
not path-prefix('/my-app/api') and 
not regex('/my-app/.*\.js') and 
regex('/my-app/.+') -> rewrite('/my-app/index.html')

Unfortunately, this doesn't seem to be rewriting anything. How can I update this configuration to property rewrite URLs?


回答1:


As a start, try this configuration in WEB-INF/undertow-handlers.conf:

path-prefix('/api') -> done
path-suffix('.js') -> done
path-prefix('/') -> rewrite('/')

You shouldn't need the /my-app prefix on any rules as they are already running in the context of your app.

However, you may need to add other predicates to prevent rewriting other resources like stylesheets, favicons, sourcemaps, etc. The full list of predicates and handlers can be helpful to produce more specific, targeted rules.

Please note, path-suffix still accounts for a path like /app?thing.js. Though you may never use a query parameter like that, it's good to keep in mind that it'll be rewritten.



来源:https://stackoverflow.com/questions/44978074/how-do-i-configure-undertow-handlers-to-support-proper-rewriting-for-spa-bookmar

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!