Skip to content

Add CORS support #18

@saw303

Description

@saw303

Introduce a way to support CORS requests.

The Spring way

Spring supports CORS out of the box.

Usually Spring uses the org.springframework.web.filter.CorsFilter to handle the CORS request. We can configure this filter by providing a org.springframework.web.cors.CorsConfigurationSource.

The generator could create such a CorsConfigurationSource for the Spring application. E.g.

@Bean
  CorsConfigurationSource corsConfigurationSource() {
    UrlBasedCorsConfigurationSource source = new UrlBasedCorsConfigurationSource();
    CorsConfiguration corsConfiguration = new CorsConfiguration();
    corsConfiguration.addAllowedOrigin("*");
    corsConfiguration.addAllowedMethod(HttpMethod.GET);
    corsConfiguration.addAllowedMethod(HttpMethod.PUT);
    corsConfiguration.addAllowedMethod(HttpMethod.POST);
    corsConfiguration.addAllowedMethod(HttpMethod.DELETE);
    corsConfiguration.addAllowedMethod(OPTIONS);
    source.registerCorsConfiguration("/**", corsConfiguration);
    return source;
  }

Java EE way

Currently not scope of this issue since the Java EE way has no priority at time.

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions