dherault / dherault/serverless-offline

How to add http proxy event ?

Open
#1,532 4 comments 1 reaction 0 assignees View on GitHub
feature question
Dominant language
JavaScript
Stars
5.3k
Forks
811
Avg merge
2d 4h
Merged PRs (30d)
3

Description

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
```

Contributor guide

Open the contributing guide

Research direction

Start with serverless-offline's resourceRoutes handling and the http-proxy event configuration for /images/{any+}. Reproduce the request to http://localhost:3000/images/images1.png against the upstream http://localhost:9999/image1.png endpoint; done means the local proxy serves the upstream image as configured.

Written by the indexing model from the issue text.

Assessment

Tech stack
aws, javascript, node.js
Domain
api, tooling
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.