如何配置Undertow处理程序以支持SPA书签的正确重写? [英] How do I configure Undertow handlers to support proper rewriting for SPA bookmarking?

查看:179
本文介绍了如何配置Undertow处理程序以支持SPA书签的正确重写?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试配置JBoss EAP 7(通过Undertow)以使用Undertow处理程序将所有SPA URL正确地重写回SPA的index.html.不幸的是,我的API位于/api,因此我需要让以/api开头的所有请求通过.

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.

这是我当前的配置(从另一个SO答案中删除):

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')

不幸的是,这似乎没有重写任何东西.如何将此配置更新为属性重写URL?

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

推荐答案

首先,请尝试在WEB-INF/undertow-handlers.conf中进行以下配置:

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

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

在任何规则上都不需要/my-app前缀,因为它们已经在您的应用程序上下文中运行.

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.

请注意,path-suffix仍占/app?thing.js之类的路径.尽管您可能永远不会使用这样的查询参数,但是请记住,它将被重写.

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.

这篇关于如何配置Undertow处理程序以支持SPA书签的正确重写?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆