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

How to add http proxy event ? #1532

Open
erwan-joly opened this issue Aug 6, 2022 · 4 comments
Open

How to add http proxy event ? #1532

erwan-joly opened this issue Aug 6, 2022 · 4 comments

Comments

@erwan-joly
Copy link

Hello,
I'm trying to understand how I can handle an http proxy event from lambda using serverless-offline.

The configuration works fine on aws api gateway but I can't find how to make it work locally.

I have a server and can access images using direct address example: http://localhost:9999/image1.png (on aws it's on a s3 bucket with cloudfront address)
I would like this to be served by the proxy a request to http://localhost:3000/images/images1.png should serve the image http://localhost:9999/image1.png

Here is a simplified version of my configuration. Is there a way to make it works on serverless-offline currently ?
I have resourceRoutes: true as the documentation suggest but it doesn't seems to work. http://localhost:3000/images/images1.png returns nothing

service: myapp
frameworkVersion: "3"
useDotenv: true
variablesResolutionMode: 20210326
disabledDeprecations:
  - CLI_OPTIONS_SCHEMA

provider:
  name: aws
  stackName: myapp
  architecture: arm64
  runtime: nodejs14.x
  region: ${opt:region, 'us-west-2'}
  stage: ${opt:stage, 'prod'}
  logRetentionInDays: 7
  lambdaHashingVersion: 20201221
  versionFunctions: false
  apiGateway:
      binaryMediaTypes:
        - '*/*'
        
  environment:
    NODE_ENV: ${self:custom.nodeenv.${self:provider.stage}}
    SERVERLESS_PROJECT: ${self:service}
    SERVERLESS_REGION: ${self:provider.region}
    SERVERLESS_STAGE: ${self:provider.stage}

package:
  individually: true

plugins:
  - serverless-webpack
  - serverless-plugin-scripts
  - serverless-offline
  
functions:
  myapp:
    memorySize: 512
    provisionedConcurrency: 0
    timeout: 6
    handler: handler.serve
    name: myapp
    events:
      - http:
            path: /images/{any+}
            method: ANY
            cors: true
            integration: http-proxy
            request:
              uri: 'http://localhost:9999/{any}'
              parameters:
                paths:
                  any: true
      - http:
          path: /
          method: any
          cors: true
		  
      - http:
          path: /{any+}
          method: any
          cors: true
          
custom:
  webpack:
    webpackConfig: "webpack.server.config.js"

  serverless-offline:
    resourceRoutes: true
    useChildProcesses: false
    noPrependStageInUrl: true
    httpPort: 3000
    lambdaPort: 3002

resources:
  Resources:
    ApiGatewayRestApi:
      Type: AWS::ApiGateway::RestApi
      Properties:
        Name: myapp
@dnalborczyk
Copy link
Collaborator

thank you for filing the issue @erwan-joly

as far as I know support for binary data types is either only partially implemented or not supported at all yet.

it's on the top of the list to support next.

@dnalborczyk
Copy link
Collaborator

possibly related: #1509

@erwan-joly
Copy link
Author

@dnalborczyk issue is not really about binary data types here but the http proxy part. I only get 204 No Content. If I had binary issue I would still expect a content with corrupted data

@erwan-joly
Copy link
Author

I tried to fix it myself https://github.com/erwan-joly/serverless-offline/pull/1/files but it seems like my knowledge of this codebase is not big enough. The new seems to return 404

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

No branches or pull requests

2 participants