Skip to content

Commit a75767a

Browse files
committed
Version 2.0.2.
1 parent fa46211 commit a75767a

File tree

5 files changed

+35
-22
lines changed

5 files changed

+35
-22
lines changed

ChangeLog.md

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,17 @@
11
# Changelog for aws-lambda-haskell-runtime-wai
22

3+
## 2.0.2
4+
5+
* Make registering multiple wai handlers possible (via `waiHandler`).
6+
* Use version `4.1.1` of `aws-lambda-haskell-runtime`.
7+
38
## 2.0.1
49

5-
* Using version `4.1.0` of `aws-lambda-haskell-runtime` that fixes [#101](https://github.com/theam/aws-lambda-haskell-runtime/issues/101).
10+
* Use version `4.1.0` of `aws-lambda-haskell-runtime` that fixes [#101](https://github.com/theam/aws-lambda-haskell-runtime/issues/101).
611

712
## 2.0.0
813

9-
* Using version [`4.0.0`](https://github.com/theam/aws-lambda-haskell-runtime/pull/97) of `aws-lambda-haskell-runtime`.
14+
* Use version [`4.0.0`](https://github.com/theam/aws-lambda-haskell-runtime/pull/97) of `aws-lambda-haskell-runtime`.
1015
* New handler types that allow you to support ALB or even API Gateway + ALB at once.
1116

1217
## 1.0.3

package.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
name: aws-lambda-haskell-runtime-wai
2-
version: 2.0.1
2+
version: 2.0.2
33
github: "eir-forsakring/aws-lambda-haskell-runtime-wai"
44
license: BSD3
55
author: "Dobromir Nikolov"

src/Aws/Lambda/Wai.hs

Lines changed: 23 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ module Aws.Lambda.Wai
1414
ALBWaiHandler,
1515
ignoreALBPathPart,
1616
ignoreNothing,
17+
waiHandler
1718
)
1819
where
1920

@@ -48,6 +49,8 @@ type ApiGatewayWaiHandler = ApiGatewayRequest Text -> Context Application -> IO
4849

4950
type ALBWaiHandler = ALBRequest Text -> Context Application -> IO (Either (ALBResponse Text) (ALBResponse Text))
5051

52+
type GenericWaiHandler = Value -> Context Application -> IO (Either Value Value)
53+
5154
newtype ALBIgnoredPathPortion = ALBIgnoredPathPortion {unALBIgnoredPathPortion :: Text}
5255

5356
data WaiLambdaProxyType
@@ -62,21 +65,26 @@ runWaiAsProxiedHttpLambda ::
6265
IO ()
6366
runWaiAsProxiedHttpLambda options ignoredAlbPath handlerName mkApp =
6467
runLambdaHaskellRuntime options mkApp id $
65-
addStandaloneLambdaHandler handlerName $ \(request :: Value) context ->
66-
case parse parseIsAlb request of
67-
Success isAlb -> do
68-
if isAlb
69-
then case fromJSON @(ALBRequest Text) request of
70-
Success albRequest ->
71-
bimap toJSON toJSON <$> albWaiHandler ignoredAlbPath albRequest context
72-
Error err -> error $ "Could not parse the request as a valid ALB request: " <> err
73-
else case fromJSON @(ApiGatewayRequest Text) request of
74-
Success apiGwRequest ->
75-
bimap toJSON toJSON <$> apiGatewayWaiHandler apiGwRequest context
76-
Error err -> error $ "Could not parse the request as a valid API Gateway request: " <> err
77-
Error err ->
78-
error $
79-
"Could not parse the request as a valid API Gateway or ALB proxy request: " <> err
68+
addStandaloneLambdaHandler handlerName (waiHandler ignoredAlbPath)
69+
70+
waiHandler ::
71+
Maybe ALBIgnoredPathPortion ->
72+
GenericWaiHandler
73+
waiHandler ignoredAlbPath request context =
74+
case parse parseIsAlb request of
75+
Success isAlb -> do
76+
if isAlb
77+
then case fromJSON @(ALBRequest Text) request of
78+
Success albRequest ->
79+
bimap toJSON toJSON <$> albWaiHandler ignoredAlbPath albRequest context
80+
Error err -> error $ "Could not parse the request as a valid ALB request: " <> err
81+
else case fromJSON @(ApiGatewayRequest Text) request of
82+
Success apiGwRequest ->
83+
bimap toJSON toJSON <$> apiGatewayWaiHandler apiGwRequest context
84+
Error err -> error $ "Could not parse the request as a valid API Gateway request: " <> err
85+
Error err ->
86+
error $
87+
"Could not parse the request as a valid API Gateway or ALB proxy request: " <> err
8088
where
8189
parseIsAlb :: Value -> Parser Bool
8290
parseIsAlb = withObject "Request" $ \obj -> do

stack.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ packages:
4040
# commit: e7b331f14bcffb8367cd58fbfc8b40ec7642100a
4141
#
4242
extra-deps:
43-
- aws-lambda-haskell-runtime-4.1.0@sha256:4fbf9855326ed0173c3ef27c006412c8da46f84b0566fa92a44ad0e988432d82,2916
43+
- aws-lambda-haskell-runtime-4.1.1@sha256:c3b3452d3a7f36950c22760fe44b51d49b43624fa3a0253e5bfc3d94809bb8fd,3024
4444
# Override default flag values for local packages and extra-deps
4545
# flags: {}
4646

stack.yaml.lock

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,12 @@
55

66
packages:
77
- completed:
8-
hackage: aws-lambda-haskell-runtime-4.1.0@sha256:4fbf9855326ed0173c3ef27c006412c8da46f84b0566fa92a44ad0e988432d82,2916
8+
hackage: aws-lambda-haskell-runtime-4.1.1@sha256:c3b3452d3a7f36950c22760fe44b51d49b43624fa3a0253e5bfc3d94809bb8fd,3024
99
pantry-tree:
1010
size: 1453
11-
sha256: c01167c71d6e25a33b822629d5efc50818589e33e5341ee1bea1bb4e2c59f9c6
11+
sha256: b7e8426edb0b5d06713a26362308abbec03379e1f3ad9c6d63973088ad75cf62
1212
original:
13-
hackage: aws-lambda-haskell-runtime-4.1.0@sha256:4fbf9855326ed0173c3ef27c006412c8da46f84b0566fa92a44ad0e988432d82,2916
13+
hackage: aws-lambda-haskell-runtime-4.1.1@sha256:c3b3452d3a7f36950c22760fe44b51d49b43624fa3a0253e5bfc3d94809bb8fd,3024
1414
snapshots:
1515
- completed:
1616
size: 532377

0 commit comments

Comments
 (0)