Skip to content

Simple request forwarder that can be exposed publicly (through a tunnel) to forward requests to local apps under development.

License

Notifications You must be signed in to change notification settings

klevo/request-sink

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

41 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

RequestSink

Simple request forwarder that can be exposed publicly (through a tunnel) to forward requests to local apps under development.

This is useful if you have some kind of a push API you want to develop against, and you want to receive requests from such API, safely, on your localhost.

Why not just expose the other app in question instead? Well usually it's going to be something like a Rails app, running in development mode. You don't want to expose such codebase in development mode to public internet directly, due to the large attack surface and possible disclosure of sensitive information.

Setup

bundle install

Run it in development

If you're developing on RequestSink, run it as follows. Code reloading is enabled.

Let's say you're running a Rails app on localhost port 3000. To forward requests that hit RequestSink you can do:

FORWARD_TO="http://localhost:3000" FORWARD_HEADERS="X_FORWARDED_FOR X_API_KEY" bundle exec rerun "rackup -p 3033"

FORWARD_TO environment variable is required and should contain a fully qualified URI. It can also contain a path, however always ommit the trailing /.

FORWARD_HEADERS allows you to specify extra HTTP headers to forward to the target. For example, if you're using some kind of API authentication, you might want to forward the appropriate header. The list of headers is space seprated. Do not add the HTTP_ header prefix, i.e. instead of HTTP_X_FORWARDED_FOR specify it as just X_FORWARDED_FOR.

Run in production

For all other uses outside of developing on the codebase, run in production mode:

FORWARD_TO="http://localhost:3000" FORWARD_HEADERS="X_FORWARDED_FOR X_API_KEY" RACK_ENV=production bundle exec rackup -p 3033

To expose KitcheSink on the public internet, use something like Cloudflare tunnel or ngrok.

Testing

Testing sending a JSON payload to KitchenSink. Returns status code from the target it forwarded the request to:

curl -X POST http://127.0.0.1:3033/any/path \
  -H 'Content-Type: application/json' \
  -d '{"sample":"json"}' \
  -w '%{http_code}'

or with a different request method:

curl -X PUT http://127.0.0.1:3033/any/path  \
  -H 'Content-Type: application/json' \
  -d '{"sample":"json"}' \
  -w '%{http_code}'

curl -X GET http://127.0.0.1:3033/install/df2f6bb1f80423801e504a276a67f0

About

Simple request forwarder that can be exposed publicly (through a tunnel) to forward requests to local apps under development.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages