File tree Expand file tree Collapse file tree 3 files changed +16
-2
lines changed
src/main/kotlin/com/batchofcode/runtimelocal Expand file tree Collapse file tree 3 files changed +16
-2
lines changed Original file line number Diff line number Diff line change @@ -2,4 +2,5 @@ package com.batchofcode.runtimelocal.config
22
33object EnvConfig {
44 val port = System .getProperty(" runtime.port" )?.toInt() ? : System .getenv(" RUNTIME_PORT" )?.toInt() ? : 9000
5+ val debug = System .getProperty(" runtime.debug" )?.toBoolean() ? : System .getenv(" RUNTIME_DEBUG" )?.toBoolean() ? : false
56}
Original file line number Diff line number Diff line change @@ -9,6 +9,7 @@ import org.http4k.core.Status.Companion.BAD_REQUEST
99import org.http4k.core.Status.Companion.OK
1010import org.http4k.format.Jackson.json
1111import org.http4k.lens.Header
12+ import org.http4k.lens.LensFailure
1213import org.http4k.lens.string
1314import org.http4k.routing.RoutingHttpHandler
1415import org.http4k.routing.bind
@@ -44,7 +45,12 @@ object InvocationHandler {
4445 }
4546
4647 fun response (): HttpHandler = handler@{
47- val requestBody = Body .json().toLens()(it)
48+ val requestBody = try {
49+ Body .json().toLens()(it).toString()
50+ }
51+ catch (ex: LensFailure ) {
52+ Body .string(ContentType .TEXT_PLAIN ).toLens()(it)
53+ }
4854 val traceIdHeader = Header .optional(" _X_AMZN_TRACE_ID" )(it)
4955 val requestId = it.path(" requestId" ) ? : return @handler Response (BAD_REQUEST ).with (
5056 Body .string(ContentType .TEXT_PLAIN ).toLens() of " Missing Request ID"
Original file line number Diff line number Diff line change @@ -2,14 +2,21 @@ package com.batchofcode.runtimelocal.handler
22
33import com.batchofcode.runtimelocal.config.EnvConfig
44import org.http4k.core.then
5+ import org.http4k.filter.DebuggingFilters
56import org.http4k.filter.ServerFilters
67import org.http4k.server.ApacheServer
78import org.http4k.server.asServer
89
910fun main () {
1011 val port = EnvConfig .port
1112
12- ServerFilters .CatchAll ()
13+ var filterChain = ServerFilters .CatchAll ()
14+ if (EnvConfig .debug) {
15+ println (" REQUEST/RESPONSE DEBUG MODE ENABLED" )
16+ filterChain = filterChain.then(DebuggingFilters .PrintRequestAndResponse ())
17+ }
18+
19+ filterChain
1320 .then(Routes ())
1421 .asServer(ApacheServer (port)).start()
1522
You can’t perform that action at this time.
0 commit comments