jhipster 刷新网址导致“无法获取/用户管理"; [英] jhipster refresh url cause "Cannot GET /user-management"
问题描述
我成功创建了一个jhipster应用,然后用admin/admin登录,点击user-management,一切正常,url变为localhost:9000/user-management.
I create a jhipster app successfully, then login with admin/admin, click user-management, all works, the url changes to localhost:9000/user-management.
但是,当我使用 chrome 刷新按钮刷新 url 时,页面被破坏并显示消息:Cannot GET/user-management",按 F12 启动调试器后,控制台中出现以下错误消息:
However, when I refresh url using chrome refresh button, the page broken with message: "Cannot GET /user-management", after press F12 to launch debugger, it has below error message in console:
拒绝执行内联脚本,因为它违反了以下内容安全策略指令:default-src 'self'".启用内联执行需要unsafe-inline"关键字、哈希(sha256-GKWAMtgBzlCzmucztJIeDl/kD0MKNqAT5HDcFIff2+A=')或随机数(nonce-...").另请注意,未明确设置script-src",因此使用default-src"作为后备.
Refused to execute inline script because it violates the following Content Security Policy directive: "default-src 'self'". Either the 'unsafe-inline' keyword, a hash ('sha256-GKWAMtgBzlCzmucztJIeDl/kD0MKNqAT5HDcFIff2+A='), or a nonce ('nonce-...') is required to enable inline execution. Note also that 'script-src' was not explicitly set, so 'default-src' is used as a fallback.
请帮忙,提前致谢.
注:yarn v1.3.2, "@angular/core": "5.2.0", java 1.8, jwt, elasticsearch, Chinese, mysql, angular 5
Note: yarn v1.3.2, "@angular/core": "5.2.0", java 1.8, jwt, elastic search, Chinese, mysql, angular 5
推荐答案
如果您设置 useHash: false
并单击刷新,请求将发送到服务器,因此您会得到这个确切的错误: 服务器正在处理的客户端路由未找到.因此,您必须使用 servlet 过滤器调整服务器端,请参阅 https 中的详细信息://github.com/jhipster/generator-jhipster/issues/4794#issuecomment-304097246
If you set useHash: false
and click on refresh, the request is sent to the server so you get this exact error you had: a client route being processed by server and not found. So you must adapt the server side using a servlet filter, see details in https://github.com/jhipster/generator-jhipster/issues/4794#issuecomment-304097246
另请注意,这种方法不适用于微服务架构中的网关.
Please note also that this approach does not easily work for gateways in microservices architecture.
以下是此类过滤器的示例,您可以对其进行调整,并将客户端路由请求转发到/",以便 index.html 中的 angular 应用程序对其进行解释:
Here is an example of such a filter that you can adapt and which forwards requests for client routes to '/' so that they get interpreted by the angular app in index.html:
public class AngularRouteFilter extends OncePerRequestFilter {
// add the values you want to redirect for
private static final Pattern PATTERN = Pattern.compile("^/((api|swagger-ui|management|swagger-resources)/|favicon\\.ico|v2/api-docs).*");
@Override
protected void doFilterInternal(HttpServletRequest request,
HttpServletResponse response,
FilterChain filterChain)
throws ServletException, IOException {
if (isServerRoute(request)) {
filterChain.doFilter(request, response);
} else {
RequestDispatcher rd = request.getRequestDispatcher("/");
rd.forward(request, response);
}
}
protected static boolean isServerRoute(HttpServletRequest request) {
if (request.getMethod().equals("GET")) {
String uri = request.getRequestURI();
return PATTERN.matcher(uri).matches();
}
return true;
}
}
这篇关于jhipster 刷新网址导致“无法获取/用户管理";的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!