diff options
author | zachdriver <zach@driver.xyz> | 2018-02-22 11:31:51 -0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2018-02-22 11:31:51 -0800 |
commit | d48406367be713fe8fd24f8dea15545817906cd4 (patch) | |
tree | 0ae98459f1c3d28953922a0ab1170fa83fc5f85b /src/main/scala/xyz/driver/core/app/DriverApp.scala | |
parent | d534ce2309052329506b31b17ae137950757890f (diff) | |
parent | 2059634d2fa2c28ddf2b992bc36ab3d96f3c2512 (diff) | |
download | driver-core-d48406367be713fe8fd24f8dea15545817906cd4.tar.gz driver-core-d48406367be713fe8fd24f8dea15545817906cd4.tar.bz2 driver-core-d48406367be713fe8fd24f8dea15545817906cd4.zip |
Merge pull request #104 from drivergroup/zsmith/reject-corsv1.8.2
Respond with correct cors headers for all rejections
Diffstat (limited to 'src/main/scala/xyz/driver/core/app/DriverApp.scala')
-rw-r--r-- | src/main/scala/xyz/driver/core/app/DriverApp.scala | 33 |
1 files changed, 3 insertions, 30 deletions
diff --git a/src/main/scala/xyz/driver/core/app/DriverApp.scala b/src/main/scala/xyz/driver/core/app/DriverApp.scala index df80c3d..1ded4dd 100644 --- a/src/main/scala/xyz/driver/core/app/DriverApp.scala +++ b/src/main/scala/xyz/driver/core/app/DriverApp.scala @@ -2,7 +2,6 @@ package xyz.driver.core.app import akka.actor.ActorSystem import akka.http.scaladsl.marshallers.sprayjson.SprayJsonSupport -import akka.http.scaladsl.model.StatusCodes._ import akka.http.scaladsl.model._ import akka.http.scaladsl.model.headers._ import akka.http.scaladsl.server.Directives._ @@ -42,7 +41,6 @@ class DriverApp( port: Int = 8080, tracer: Tracer = NoTracer)(implicit actorSystem: ActorSystem, executionContext: ExecutionContext) { self => - import DriverApp._ implicit private lazy val materializer: ActorMaterializer = ActorMaterializer()(actorSystem) private lazy val http: HttpExt = Http()(actorSystem) @@ -73,8 +71,9 @@ class DriverApp( val swaggerRoute = swaggerService.routes ~ swaggerService.swaggerUI val versionRt = versionRoute(version, gitHash, time.currentTime()) val basicRoutes = new DriverRoute { - override def log: Logger = self.log - override def route: Route = versionRt ~ healthRoute ~ swaggerRoute + override def log: Logger = self.log + override def config: Config = self.config + override def route: Route = versionRt ~ healthRoute ~ swaggerRoute } val combinedRoute = modules.map(_.route).foldLeft(basicRoutes.routeWithDefaults)(_ ~ _) @@ -221,29 +220,3 @@ class DriverApp( }) } } - -object DriverApp { - implicit def rejectionHandler: RejectionHandler = - RejectionHandler - .newBuilder() - .handleAll[MethodRejection] { rejections => - val methods = rejections map (_.supported) - lazy val names = methods map (_.name) mkString ", " - - options { ctx => - optionalHeaderValueByType[Origin](()) { originHeader => - respondWithHeaders(List[HttpHeader]( - Allow(methods), - `Access-Control-Allow-Methods`(methods), - allowOrigin(originHeader), - `Access-Control-Allow-Headers`(AllowedHeaders: _*), - `Access-Control-Expose-Headers`(AllowedHeaders: _*) - )) { - complete(s"Supported methods: $names.") - } - }(ctx) - } ~ - complete(MethodNotAllowed -> s"HTTP method not allowed, supported methods: $names!") - } - .result() -} |