vapor-community / vapor-aws-lambda-runtime

Run your Vapor api server on AWS Lambda using the official Swift Server runtime.
Apache License 2.0
104 stars 10 forks source link

Bugfix/upstream stream io fix #11

Closed fcobia closed 3 years ago

fcobia commented 3 years ago

This PR would replace my previous PR. While running a Leaf based app, I noticed that the CSS and JavaScript files were not being served up properly. They were returning status code 200, but contained 0 bytes. I discovered that the FileMiddleware is using streaming for the files, but the conversion from Vapor Response to Lambda response did not handle this case.

I have fixed this, but I had to change the API a little because the fix requires the use of promises and event loops.

I spent a little time looking into doing some tests, but that requires creating a Lambda.Context object and all the APIs I could find for doing are marked internal and are therefore inaccessible. If you have any pointers into how I might do that, I would be happy to look into creating some test requests.

codecov[bot] commented 3 years ago

Codecov Report

Merging #11 into main will decrease coverage by 0.00%. The diff coverage is 0.00%.

Impacted file tree graph

@@           Coverage Diff            @@
##            main     #11      +/-   ##
========================================
- Coverage   0.02%   0.02%   -0.01%     
========================================
  Files        509     531      +22     
  Lines      36361   39630    +3269     
========================================
  Hits           8       8              
- Misses     36353   39622    +3269     
Impacted Files Coverage Δ
Sources/VaporAWSLambdaRuntime/APIGateway.swift 0.00% <ø> (ø)
Sources/VaporAWSLambdaRuntime/APIGatewayV2.swift 0.00% <0.00%> (ø)
Sources/VaporAWSLambdaRuntime/LambdaServer.swift 0.00% <ø> (ø)
.build/checkouts/swift-nio/Sources/NIO/Heap.swift 0.00% <0.00%> (ø)
...build/checkouts/swift-nio/Sources/NIO/Socket.swift 0.00% <0.00%> (ø)
...build/checkouts/swift-nio/Sources/NIO/System.swift 0.00% <0.00%> (ø)
...uild/checkouts/swift-nio/Sources/NIO/Channel.swift 0.00% <0.00%> (ø)
...ild/checkouts/swift-nio/Sources/NIO/PipePair.swift 0.00% <0.00%> (ø)
...ld/checkouts/swift-nio/Sources/NIO/Bootstrap.swift 0.00% <0.00%> (ø)
...ld/checkouts/swift-nio/Sources/NIO/EventLoop.swift 0.00% <0.00%> (ø)
... and 89 more

Continue to review full report at Codecov.

Legend - Click here to learn more Δ = absolute <relative> (impact), ø = not affected, ? = missing data Powered by Codecov. Last update 7a35ef5...62acd6d. Read the comment docs.

fabianfett commented 3 years ago

@fcobia Oh my god! I'm so sorry for not having reviewed this yet. I thought I had but apparently, I didn't. So Sorry.

fcobia commented 3 years ago

I am new to Swift NIO and Vapor, so I am just trying to find my way through it. I took your changes and I re-ran my website in AWS and it works.

fabianfett commented 3 years ago

@fcobia awesome. Do you want to run swiftformat .? If that's done, this is ready to merge. Thanks so much! This looks great!

fcobia commented 3 years ago

Done