Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

base64 encoding occurs for application/javascript #55

Closed
jcouser opened this issue Feb 25, 2018 · 4 comments
Closed

base64 encoding occurs for application/javascript #55

jcouser opened this issue Feb 25, 2018 · 4 comments

Comments

@jcouser
Copy link

jcouser commented Feb 25, 2018

I'm not sure if/how I'm getting this behavior but unless I've added this mime type (application/javascript) here:
https://github.com/logandk/serverless-wsgi/blob/master/wsgi.py#L16

All of my javascript files loading in are base64 encoded and break rendering. I've adding this mime type and everything is fixed. This seems like a bug unless I'm overlooking something in configuration.

@logandk
Copy link
Owner

logandk commented Feb 25, 2018

That does seem odd. Even though application/javascript is indeed not on the list of text mime-types, it should not end up being base64 encoded in the response. The WSGI handler base64 encodes the payload and sets the isBase64Encoded, instructing API Gateway to decode the payload, thus sending the original javascript to the client.

I'm fine with adding the mime-type, but I'd like to see a simple reproduction case in order to find the actual root cause. Could you help out by providing a simple configuration that reproduces the error? Thanks!

As a side note, serving assets should ideally happen through S3/CloudFront rather than the Lambda function itself

@jcouser
Copy link
Author

jcouser commented Feb 28, 2018

Appreciate the feedback, sorry for the delayed response, was just working on this over the weekend and have been busy.

I've started with this as a base for a simple flask based serverless application which works fine. I've then replaced the requirements.txt, app.py and serverless.yml to support flask-restplus which is a REST framework for flask that provides swagger-ui built in, so these js files are built within this package:

http://flask-restplus.readthedocs.io/en/stable/

I've attached a zip that contains the requirements, app.py to support flask-restplus, as well as the updated serverless.yml.
sls flask-restplus.zip

Let me know if this helps, or if I can provide anything further from the project.

@logandk
Copy link
Owner

logandk commented Mar 3, 2018

Don't worry, I haven't had time to look into this yet myself. Thanks for the attached files, I'll try to reproduce it.

@logandk
Copy link
Owner

logandk commented Mar 11, 2018

After testing this, as far as I can tell, there is some special handling of application/javascript going on in API Gateway. The other assets are passed along fine as base64 encoded, but the JS files doesn't get decoded. I've added the mimetype, which makes sense either way.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants