如何将OAuth2将URI从ViewControllerRegistry中排除,因为它在该路径上没有 /API

发布于 2025-02-13 18:01:01 字数 1167 浏览 0 评论 0原文

我有Spring Boot(后端)应用程序与React(Frontend)结合使用,因此两者都被包装为一个战争文件并部署到Tomcat Apache中,以使React路由从Spring Boot中进行工作,我必须在Spring Boot中添加配置,并且可以正常工作。下面是我添加的配置。所有包含API字符串的路径都有望按Spring Boot服务,并且也有效。

@Configuration
public class WebRouteConfig implements WebMvcConfigurer {
     
    @Override
    public void addViewControllers(ViewControllerRegistry registry) {
        // Map "/"
        registry.addViewController("/")
                .setViewName("forward:/index.html");

        // Single directory level - no need to exclude "api"
        registry.addViewController("/{x:[\\w\\-]+}")
                .setViewName("forward:/index.html");
        
        registry.addViewController("/{x:^(?!api$).*$}/{y:[\\w\\-]+}")
        .setViewName("forward:/index.html");
        // Multi-level directory path, need to exclude "api" on the first part of the path
        registry.addViewController("/{x:^(?!api$).*$}/ABC/{y:[\\w\\-]+}")
                .setViewName("forward:/index.html");
       
        
    }

但是我想在此处排除Oauth重定向URI(PATH = OAUTH/REDIRECT),因为它没有“ API”字符串,因此它正在重定向到没有为该路径配置的路由的前端。春季启动预计将接收OAuth/重定向页面,而无需路由反应路由,可以帮助我如何从注册表中排除此特定路径的注册表。

I have spring boot (backend) application combined with React(Frontend), So both are packaged as one war file and deployed into tomcat apache, In order to make react routing work from Spring boot I had to add configuration in spring boot and it works. Below is the configuration I added.All the paths that includes api strings are expected to serve by spring boot and that is working as well.

@Configuration
public class WebRouteConfig implements WebMvcConfigurer {
     
    @Override
    public void addViewControllers(ViewControllerRegistry registry) {
        // Map "/"
        registry.addViewController("/")
                .setViewName("forward:/index.html");

        // Single directory level - no need to exclude "api"
        registry.addViewController("/{x:[\\w\\-]+}")
                .setViewName("forward:/index.html");
        
        registry.addViewController("/{x:^(?!api$).*$}/{y:[\\w\\-]+}")
        .setViewName("forward:/index.html");
        // Multi-level directory path, need to exclude "api" on the first part of the path
        registry.addViewController("/{x:^(?!api$).*$}/ABC/{y:[\\w\\-]+}")
                .setViewName("forward:/index.html");
       
        
    }

But I wanted to exclude oauth redirect URI(path=oauth/redirect) here , As it does not have "api" string in that so it's being redirected to frontend where it does not have routing configured for that path. Spring boot is expected to receive oauth/redirect page without routing to react routing, could some body please help me how to exclude from the registry for this particular path.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文