Как настроить контекстный путь в приложении Jhipster (spring boot + angular) - PullRequest
0 голосов
/ 21 января 2020

Я создаю проект Jhipster classi c Spring Auth + Angular клиентское приложение.

Мне просто нужно установить собственный путь к контексту "шлюз" в приложении Jhipster

На сервере я просто установил файл "src \ main \ resources \ config \ application-dev. yml ":

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

На клиенте angular я не могу понять, как это настроить.

В файле" webpack \ webpack.common. js "есть установить:

....
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' })
....

но это не работает, вход всегда не удался. я пропускаю что-то еще?

ОБНОВЛЕНИЕ для комментария Гаэля Марзиу

Похоже, логин от клиента "http://localhost: 9000 / gateway / " не удалось войти в службу "http://localhost: 8080 / gateway / api / authentication " с кодом 403, для некоторых исключений csfr на сервере:

Resolved [org. springframework.security.web.csrf. @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 }

1 Ответ

0 голосов
/ 12 апреля 2020

Я нашел следующие 5 мест.

webpack.common. js

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

webpack.dev. js

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

app.context .ts

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

resources \ config \ application-dev.yml

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

index. html

<base href="/gateway/" />
...