All Downloads are FREE. Search and download functionalities are using the official Maven repository.

spice.http.server.CORSSupport.scala Maven / Gradle / Ivy

There is a newer version: 0.6.1
Show newest version
package spice.http.server
import cats.effect.IO
import spice.http.{Headers, HttpExchange}

trait CORSSupport extends HttpServer {
  protected def allowOrigin: String = "*"

  override protected def preHandle(exchange: HttpExchange): IO[HttpExchange] = super
    .preHandle(exchange)
    .flatMap { exchange =>
      exchange.modify { response =>
        IO.pure(response.withHeader(Headers.Response.`Access-Control-Allow-Origin`(allowOrigin)))
      }
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy