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
2
2
3
3
object EnvConfig {
4
4
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
5
6
}
Original file line number Diff line number Diff line change @@ -9,6 +9,7 @@ import org.http4k.core.Status.Companion.BAD_REQUEST
9
9
import org.http4k.core.Status.Companion.OK
10
10
import org.http4k.format.Jackson.json
11
11
import org.http4k.lens.Header
12
+ import org.http4k.lens.LensFailure
12
13
import org.http4k.lens.string
13
14
import org.http4k.routing.RoutingHttpHandler
14
15
import org.http4k.routing.bind
@@ -44,7 +45,12 @@ object InvocationHandler {
44
45
}
45
46
46
47
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
+ }
48
54
val traceIdHeader = Header .optional(" _X_AMZN_TRACE_ID" )(it)
49
55
val requestId = it.path(" requestId" ) ? : return @handler Response (BAD_REQUEST ).with (
50
56
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
2
2
3
3
import com.batchofcode.runtimelocal.config.EnvConfig
4
4
import org.http4k.core.then
5
+ import org.http4k.filter.DebuggingFilters
5
6
import org.http4k.filter.ServerFilters
6
7
import org.http4k.server.ApacheServer
7
8
import org.http4k.server.asServer
8
9
9
10
fun main () {
10
11
val port = EnvConfig .port
11
12
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
13
20
.then(Routes ())
14
21
.asServer(ApacheServer (port)).start()
15
22
You can’t perform that action at this time.
0 commit comments