JetBrains / kotless

Kotlin Serverless Framework
Apache License 2.0
1.15k stars 57 forks source link

Enable CORS check #85

Open sitole opened 3 years ago

sitole commented 3 years ago

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.

hamadycisse commented 3 years ago

Same issue here

mamaorha commented 1 year ago

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