Comments (9)
You control how/when to gzip in your app.
This library will base64 encoded responses when the content-type matches one you specify in the binaryMimeTypes list (third param of createServer). In order for this to be encoded correctly in the final response to the client, you must also specify your binary mime types on API Gateway.
Replied to your comment in #39 also which I assume is the same issue.
from serverless-express.
The response flow looks like:
Express response -> compression/gzip middleware (if you use it) -> aws-serverless-express (encodes to base64 if content-type is specified in binaryMimeTypes in Lambda handler) -> API Gateway (decodes base64 if content-type matches a binary mime type specified on API) -> Client
If client receives base64, it indicates your API binary support needs to be configured and redeployed.
from serverless-express.
Thanks @brettstack, I've already configured API Gateway through Swagger with SAM, similar to how it is done in the example. That is, my Swagger template contains:
x-amazon-apigateway-binary-media-types:
- application/json
at its root, and my code contains
const binaryMimeTypes = [
'application/json',
];
const server = awsServerlessExpress.createServer(app, null, binaryMimeTypes)
I've also made sure that changes to the API have been applied through the SAM stack. My list of binary types for this API in the Console indeed contains application/json
. The only other thing I could think of is that SAM somehow didn't re-deploy these changes to the stage even though it applied them to the API resource itself.
EDIT: I re-deployed it manually and that had no effect..
from serverless-express.
Ok sorry for trouble, it seems that API Gateway doesn't understand application/json
in its list of binary types. When I switched it to '*/*'
, it started working! Both when I send accept-encoding
and when I don't.
from serverless-express.
I guess the after-thought question is, why does API Gateway ignore application/json
and only accept */*
?
from serverless-express.
from serverless-express.
I swear I've tried that before, but now it works too, thanks!
I also was under impression that API Gateway would assume 'application/json' automatically if Accept is omitted, at least according to these docs: http://docs.aws.amazon.com/apigateway/latest/developerguide/request-response-data-mappings.html#transforming-request-response-body
It looks like that doesn't apply in this case (either because of binary support or the library or proxy integration).
from serverless-express.
Correct, mapping templates to not apply to Lambda Proxy
from serverless-express.
I still think there's an issue regarding Accept-Enconding
headers. The same mime type should have two different outputs depending on the Accept-Encoding
header:
If a client accepts gzip
, then a mime type application/javascript
will for sure reply with a binary content. But if the client request does not accept a gzipped file, it will still be served a [broken] binary file, because we specified that this mime type should be handled as such.
from serverless-express.
Related Issues (20)
- requests to /foo/bar to an API Gateway (v1) resource of /foo/{proxy+} return 404 as they are routed to /bar HOT 5
- Can't access static files behind Cloudfront
- Logger doesn't work HOT 3
- [404 Not Found] API Gateway HTTP Protocol Path Matching with stage HOT 3
- `body` data not passed correctly to the express app HOT 1
- Unable to Stream Responses from AWS Lambda HOT 5
- Is there support for NodeJS Server from HTTP module HOT 1
- Pradeep wants to pay 0 USD to have this issue fixed
- NestJS & Unable to determine event source based on event HOT 5
- RIE instructions missing
- Incompatibility with AWS API Gateway HOT 8
- Binary Content Type with Dots or Other Regex
- @codegenie/serverless-express has not been release to npm HOT 2
- NestJS + PG Aurora Serverless cold start HOT 4
- Serverless with Node14 & Yarn unable to install @vendia/serverless-express via serverless package/deploy. Pulls latest @CodeGenieApp tag instead HOT 2
- "postbuild" commnad can't work in Windows HOT 3
- `Authorization` headers not passed properly through Api Gateway v1.
- Swagger for basic-starter nestjs template
- Failing works with files
- Support hyper-express HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from serverless-express.