serverless-components / express

⚡ Take existing Express.js apps and host them easily on cheap, auto-scaling, serverless infrastructure (AWS Lambda and AWS HTTP API).
https://serverless.com/components
Apache License 2.0
376 stars 34 forks source link

Support minimumCompressionSize input #26

Open BrandynThornton opened 4 years ago

BrandynThornton commented 4 years ago

Hello,

I would like to set cors: true on my httpApi resource, is this possible using the component?

Thanks

eahefnawy commented 4 years ago

We currently don't have this built in at the API Gateway level, but you could achieve this by returning the right headers in your express app code. Here's an example from the fullstack-app template

https://github.com/serverless-components/fullstack-app/blob/master/api/app.js#L28-L35

BrandynThornton commented 4 years ago

Thanks, I had the cors npm package installed so I performed a redeploy and it started working. I think I had some manually configured CORS settings on the gateway from testing that must have been interfering.

How about support for compression? I am porting some code from aws-serverless-express and compression seems to be the only part that isn't working anymore.

I've seen some examples in serverless.yml to add the following but I'm guessing the component only supports the input options specified in the documentation.

provider: name: aws apiGateway: minimumCompressionSize: 1024

eahefnawy commented 4 years ago

@BrandynThornton how do you think that would look like with component? a new input maybe?

BrandynThornton commented 4 years ago

Yea a new input seems like the most straight-forward approach.

I'm very new to the serverless framework but I think a more powerful solution would be to support configuration options from providers such as https://www.serverless.com/framework/docs/providers/aws/events/apigateway/#compression in a component context. Perhaps it's possible to merge that configuration with the internal component resources' configuration. I understand that would be breaking the clean abstraction that components provide so it probably isn't ideal but it enables a lot of the more complex scenarios. I'm not sure if this even makes sense in a serverless.yml file but this was my first intuition after reading the non-component documentation.

app: express-starter
component: express
name: express-starter
stage: dev

provider:
  name: aws
  apiGateway:
    minimumCompressionSize: 1024

inputs:
  src: ./
  # openApi: true
  roleName: express-starter-lambda-role-us-east-1
  # Environment variables
  env:
    DB_SECRET_ARN: ${env:DBSECRETARN}
    DB_CLUSTER_ARN: ${env:DBCLUSTERARN}
eahefnawy commented 4 years ago

Sounds good. I just rephrased this issue. I think we can add this in.