Giter VIP home page Giter VIP logo

Comments (9)

brettstack avatar brettstack commented on May 22, 2024

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.

brettstack avatar brettstack commented on May 22, 2024

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.

dinvlad avatar dinvlad commented on May 22, 2024

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.

dinvlad avatar dinvlad commented on May 22, 2024

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.

dinvlad avatar dinvlad commented on May 22, 2024

I guess the after-thought question is, why does API Gateway ignore application/json and only accept */*?

from serverless-express.

brettstack avatar brettstack commented on May 22, 2024

from serverless-express.

dinvlad avatar dinvlad commented on May 22, 2024

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.

brettstack avatar brettstack commented on May 22, 2024

Correct, mapping templates to not apply to Lambda Proxy

from serverless-express.

enapupe avatar enapupe commented on May 22, 2024

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)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.