[英]Spring Boot + Angular JS JBoss deployment
我创建了 Angular JS 项目,它在端口 4200 下的节点服务器和基于 Spring Boot 的 REST 数据服务中运行作为单独的项目,它在 8080 端口下的 eclipse 中运行。 REST 服务 (RS) 部分使用基于 OAuth 的安全性并验证对 access_token 的每个请求。 这作为单独的实体工作得非常好。
现在,我尝试在 WAR 的根文件夹中使用 angular 编译输出构建单个 WAR,如果我访问应用程序(通过访问任何 URL) - 在 Angular NG-router Spring 启动安全性出现之前并拒绝无 OAuth 验证的请求。
@Override
public void configure(HttpSecurity http) throws Exception {
http.antMatcher("/**").authorizeRequests().antMatchers("/error").permitAll().anyRequest().authenticated();
http.csrf().disable();
http.headers().frameOptions().disable();
http.cors().configurationSource(new CorsConfigurationSource() {
@Override
public CorsConfiguration getCorsConfiguration(HttpServletRequest request) {
CorsConfiguration config = new CorsConfiguration();
config.setAllowedHeaders(Collections.singletonList("*"));
config.setAllowedMethods(Collections.singletonList("*"));
config.addAllowedOrigin("*");
config.setAllowCredentials(true);
return config;
}
});
}
这是我的安全配置文件。 请告知将两个单独的 WAR 合并到单个模块 EAR 中是否可以解决此问题。
查看我的存储库
有一个项目结构可以生成单一战争。
编辑:也许你需要创建一个 proxy.conf.json 文件
{
"/api/*": {
"target": "http://localhost:8080",
"secure": false
}
}
并将它添加到您的 angular.json 文件中的 architect-serve-options-proxyConfig
您的安全配置正在授权每个 url 模式。 如果您希望在调用 API 进行身份验证/授权之前加载静态内容,请从安全配置中排除 .js、.css、.html 文件。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.