如何在Jhipster(Spring Boot + Angle)应用程序上设置上下文路径 [英] How set up a Context Path on a Jhipster (spring boot + angular) application

查看:129
本文介绍了如何在Jhipster(Spring Boot + Angle)应用程序上设置上下文路径的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我生成了一个Jhipster项目的经典Spring Auth + Angular客户端应用程序.

I generate a Jhipster project classic Spring Auth + Angular client application.

我只需要在Jhipster应用程序上设置自定义上下文路径网关"

I just need to set a custom context path "gateway" on a Jhipster application

在服务器上,我仅在文件"src \ main \ resources \ config \ application-dev.yml"上设置:

On the server i just set on the file "src\main\resources\config\application-dev.yml":

.....
server:
  port: 8080
  servlet:
     context-path: /gateway
...

在有角度的客户端上,我不知道如何设置它.

On the angular client i can't understand how to set up this.

在文件"webpack \ webpack.common.js"上已设置:

On the file "webpack\webpack.common.js" is set:

....
new webpack.DefinePlugin({
    'process.env': {
        NODE_ENV: `'${options.env}'`,
        BUILD_TIMESTAMP: `'${new Date().getTime()}'`,
        // APP_VERSION is passed as an environment variable from the Gradle / Maven build tasks.
        VERSION: `'${process.env.hasOwnProperty('APP_VERSION') ? process.env.APP_VERSION : 'DEV'}'`,
        DEBUG_INFO_ENABLED: options.env === 'development',
        // The root URL for API calls, ending with a '/' - for example: `"https://www.jhipster.tech:8081/myservice/"`.
        // If this URL is left empty (""), then it will be relative to the current context.
        // If you use an API server, in `prod` mode, you will need to enable CORS
        // (see the `jhipster.cors` common JHipster property in the `application-*.yml` configurations)
        SERVER_API_URL: `'http://localhost:8080/gateway/'`
    }
}),
......        
new BaseHrefWebpackPlugin({ baseHref: '/gateway' })
....

但是它不起作用,登录总是失败.我想念其他东西吗?

but it's does'nt work , the login always failed. i miss something else?

GaëlMarziou评论的更新

似乎来自客户端" http://localhost:9000/gateway/的登录失败使用以下命令登录到服务" http://localhost:8080/gateway/api/authentication "代码403,用于服务器上的某些csfr异常:

It's seem the login from client "http://localhost:9000/gateway/" failed to login to the service "http://localhost:8080/gateway/api/authentication" with code 403, for some csfr exception on the server:

已解决的[org.springframework.security.web.csrf.MissingCsrfTokenException:由于未找到您的会话,因此无法验证提供的CSRF令牌.]

因此,Spring Boot的安全性配置可能存在一些错误:

So it's probably some error on the security configuration of spring boot :

    @Override
    public void configure(HttpSecurity http) throws Exception {
        // @formatter:off
        http
            .csrf()
            .csrfTokenRepository(CookieCsrfTokenRepository.withHttpOnlyFalse())
        .and()
            .addFilterBefore(corsFilter, CsrfFilter.class)
            .exceptionHandling()
                .authenticationEntryPoint(problemSupport)
                .accessDeniedHandler(problemSupport)
        .and()
            .rememberMe()
            .rememberMeServices(rememberMeServices)
            .rememberMeParameter("remember-me")
            .key(jHipsterProperties.getSecurity().getRememberMe().getKey())
        .and()
            .formLogin()
            .loginProcessingUrl("/api/authentication")
            .successHandler(ajaxAuthenticationSuccessHandler())
            .failureHandler(ajaxAuthenticationFailureHandler())
            .permitAll()
        .and()
            .logout()
            .logoutUrl("/api/logout")
            .logoutSuccessHandler(ajaxLogoutSuccessHandler())
            .permitAll()
        .and()
            .headers()
            .contentSecurityPolicy("default-src 'self'; frame-src 'self' data:; script-src 'self' 'unsafe-inline' 'unsafe-eval' https://storage.googleapis.com; style-src 'self' 'unsafe-inline'; img-src 'self' data:; font-src 'self' data:")
        .and()
            .referrerPolicy(ReferrerPolicyHeaderWriter.ReferrerPolicy.STRICT_ORIGIN_WHEN_CROSS_ORIGIN)
        .and()
            .featurePolicy("geolocation 'none'; midi 'none'; sync-xhr 'none'; microphone 'none'; camera 'none'; magnetometer 'none'; gyroscope 'none'; speaker 'none'; fullscreen 'self'; payment 'none'")
        .and()
            .frameOptions()
            .deny()
        .and()
            .authorizeRequests()
            .antMatchers("/**/api/authenticate").permitAll()
            .antMatchers("/**/api/register").permitAll()
            .antMatchers("/**/api/activate").permitAll()
            .antMatchers("/**/api/account/reset-password/init").permitAll()
            .antMatchers("/**/api/account/reset-password/finish").permitAll()
            .antMatchers("/**/api/**").authenticated()
            .antMatchers("/**/management/health").permitAll()
            .antMatchers("/**/management/info").permitAll()
            .antMatchers("/**/management/prometheus").permitAll()
            .antMatchers("/**/management/**").hasAuthority(AuthoritiesConstants.ADMIN);
        // @formatter:on
    }

推荐答案

我发现了以下5个地方.

I found following 5 places.

webpack.common.js

webpack.common.js

new BaseHrefWebpackPlugin({ baseHref: '/gateway/' })

webpack.dev.js

webpack.dev.js

proxy: [{
    context: [
        '/gateway/api',
        '/gateway/services',
       ...

app.context.ts

app.context.ts

export const SERVER_API_URL = process.env.SERVER_API_URL + "/gateway/";

resources \ config \ application-dev.yml

resources\config\application-dev.yml

.....
server:
  port: 8080
  servlet:
     context-path: /gateway

index.html

index.html

<base href="/gateway/" />

这篇关于如何在Jhipster(Spring Boot + Angle)应用程序上设置上下文路径的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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