jhipster刷新URL导致“无法获取/用户管理" [英] jhipster refresh url cause "Cannot GET /user-management"

查看:116
本文介绍了jhipster刷新URL导致“无法获取/用户管理"的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我成功创建了一个jhipster应用,然后使用admin/admin登录,单击用户管理",所有工作正常,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时,页面破裂并显示消息:无法获取/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,弹性搜索,中文,mysql,角度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刷新URL导致“无法获取/用户管理"的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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