aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorZach Smith <zach@driver.xyz>2018-02-08 13:02:07 -0800
committerZach Smith <zach@driver.xyz>2018-02-20 10:34:22 -0800
commit04db4e857fceeb15196d8f13d63e987ad214be38 (patch)
tree93216a3e8e618cc5d6d11d20d4d233029b42f5bd
parent7f2e90c278a28c49da5c736b0977466fed8e96cc (diff)
downloaddriver-core-04db4e857fceeb15196d8f13d63e987ad214be38.tar.gz
driver-core-04db4e857fceeb15196d8f13d63e987ad214be38.tar.bz2
driver-core-04db4e857fceeb15196d8f13d63e987ad214be38.zip
Move rejection handler to DriverRoute
-rw-r--r--src/main/resources/reference.conf17
-rw-r--r--src/main/scala/xyz/driver/core/rest/DriverRoute.scala17
2 files changed, 30 insertions, 4 deletions
diff --git a/src/main/resources/reference.conf b/src/main/resources/reference.conf
index 238ac68..f903234 100644
--- a/src/main/resources/reference.conf
+++ b/src/main/resources/reference.conf
@@ -2,7 +2,7 @@
# Default settings for driver core. Any settings defined by users of #
# this library will take precedence. See the documentation of the #
# Typesafe Config Library (https://github.com/lightbend/config) for #
-# more information. #
+# more information. #
######################################################################
# This scope is for general settings related to the execution of a
@@ -13,7 +13,20 @@ application {
cors {
allowedMethods: ["GET", "PUT", "POST", "PATCH", "DELETE", "OPTIONS"]
- allowedOrigins: []
+ allowedOrigins: [
+ {
+ scheme: http
+ hostSuffix: localhost
+ },
+ {
+ scheme: https
+ hostSuffix: driver.xyz
+ },
+ {
+ scheme: https
+ hostSuffix: driver.network
+ }
+ ]
}
}
diff --git a/src/main/scala/xyz/driver/core/rest/DriverRoute.scala b/src/main/scala/xyz/driver/core/rest/DriverRoute.scala
index 1fe5e3f..5e629be 100644
--- a/src/main/scala/xyz/driver/core/rest/DriverRoute.scala
+++ b/src/main/scala/xyz/driver/core/rest/DriverRoute.scala
@@ -6,7 +6,7 @@ import akka.http.scaladsl.model._
import akka.http.scaladsl.model.StatusCodes
import akka.http.scaladsl.model.headers._
import akka.http.scaladsl.server.Directives._
-import akka.http.scaladsl.server.{Directive0, ExceptionHandler, RequestContext, Route}
+import akka.http.scaladsl.server._
import com.typesafe.config.Config
import com.typesafe.scalalogging.Logger
import org.slf4j.MDC
@@ -22,7 +22,7 @@ trait DriverRoute {
def route: Route
def routeWithDefaults: Route = {
- (defaultResponseHeaders & handleExceptions(ExceptionHandler(exceptionHandler))) {
+ (defaultResponseHeaders & handleRejections(rejectionHandler) & handleExceptions(ExceptionHandler(exceptionHandler))) {
route ~ defaultOptionsRoute
}
}
@@ -84,6 +84,19 @@ trait DriverRoute {
}
}
+ protected def rejectionHandler: RejectionHandler =
+ RejectionHandler
+ .newBuilder()
+ .handle {
+ case rejection =>
+ respondWithAllCorsHeaders {
+ RejectionHandler
+ .default(scala.collection.immutable.Seq(rejection))
+ .getOrElse(complete("OK"))
+ }
+ }
+ .result()
+
/**
* Override me for custom exception handling
*