[英]Reloading Angular app running in docker gives 500 Internal Server Error
我正在开发一个 Angular 应用程序,BE 在 Java/Spring-Boot 中。 不知何故,我能够在除 /management/** 之外的每个视图中执行重新加载或直接在浏览器中直接复制地址。
www.site-name.com/inscription (工作) www.site-name.com/management/utilisateurs (不工作)
这些是我在 Angular 中的路由配置
const routes: Routes = [
{
path: '',
redirectTo: '/home',
pathMatch: 'full'
},
{
path: 'home',
component: IntroPageComponent,
canActivate: [HomeGuard]
},
{
path: '',
loadChildren: () => import('../user-auth/').then(module => module.UserAuthModule),
},
{
path: 'inscription',
loadChildren: () => import('../inscription').then(module => module.InscriptionModule),
canActivateChild: [AuthenticatedGuard, InscriptionGuard]
},
{
path: 'management',
loadChildren: () => import('../management').then(module => module.ManagementModule),
canActivateChild: [AuthenticatedGuard, ManagementGuard]
},
{
path: '**',
redirectTo: '/home'
}
];
然后管理模块有自己的路由配置
const routes: Routes = [
{
path: 'utilisateurs',
component: UsersComponent,
resolve: { man : ManagementPreload }
},
"more routes here"
];
Spring controller 提供索引。html
@GetMapping({
"/",
"/home",
"/incription",
"/management/**",
......
})
public String index() {
return "index";
}
和 dockerfile
FROM openjdk:8-jdk-alpine
VOLUME /tmp
ARG JAR_FILE
ARG APP_NAME
COPY ${JAR_FILE} app.jar
ENTRYPOINT ["java","-Djava.security.egd=file:/dev/./urandom","-jar","/app.jar", "--file:/app/config/application-siteinscription.properties", "-XX:+UseG1GC"]
我设法弄清楚问题是什么并实施了一个我不确定它是否是最合适的解决方案,但我会在这里为其他有同样问题的人发布它,也许可以就如何实施更好的解决方案获得一些反馈.
值得一提的是,angular 路由配置没有任何问题。
该问题与 SpringMVC ViewResolver(s) 有关
根据我的配置
@GetMapping({
"/",
"/home",
"/incription",
"/management/**",
......
})
public String index() {
return "index";
}
当 Spring ViewResolver 看到类似的路线时
/management/**
它将尝试查找视图索引并根据配置返回它,例如
/path/to/resource/management/index.html
我所需要的只是无论路线总是返回
/path/to/resource/index.html
我设法使应用程序按照我的需要工作而没有太多开销的方法就是简单地实现 controller 之类的
@GetMapping({
"/",
"/home",
"/auth",
"/inscription",
...
})
public String index() {
return "index";
}
@GetMapping("/management/**")
public ModelAndView forwardToHome() {
return new ModelAndView("forward:/home", new ModelMap());
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.