JetBrains/kotless

Enable CORS check

sitole opened this issue · 2 comments

Hello,
i want to connect my frontend website with Spring Kotless deployed in Lambda function, but Kotless and API gateway does not accept OPTIONS HTTP request for CORS check.

Same issue here

hi, i had same issue i had to hack it by adding the following:

@Component
open class CorsConfiguration : OncePerRequestFilter() {
    override fun doFilterInternal(
        httpServletRequest: HttpServletRequest,
        httpServletResponse: HttpServletResponse,
        filterChain: FilterChain
    ) {
        httpServletResponse.addHeader("Access-Control-Allow-Origin", "*")
        httpServletResponse.addHeader("Access-Control-Allow-Headers", "*")
        httpServletResponse.addHeader("Access-Control-Allow-Methods", "*")

        filterChain.doFilter(httpServletRequest, httpServletResponse);
    }
}

after adding those go to api-gateway and enable cors per endpoint (its a pain)

  1. go to api gateway
  2. pick your api
  3. pick each method and go its "method response", add an http status like 200
  4. go to actions -> enable cors