Giter Club home page Giter Club logo

proxybootstrap's Introduction

CORS reverse development proxy

Build Status PyPI License PyPI Version PyPI Python versions

A simple yet extensible python wrapper script for templating a proxy nginx configuration that functions as host mapped reverse proxy container.

Why and when to use?

Modern browsers enforce CORS policy and won't let you make requests from your frontend running on localhost:8080 to your backend at localhost:4000. To solve this problem, start a proxy at localhost:5000 (or any other spare port) and proxy requests based on paths:

  • localhost:5000/api and localhost:5000/buy will be routed to the backend localhost:4000
  • localhost:5000/ will be routed to the frontend localhost:8080

Installation and usage

pip install proxybootstrap # using pip

Note: You will need docker for running the proxy container

Start the proxy server with your configuration

proxybootstrap \
    --port 5000 \
    /api@http://127.0.0.1:4000 /buy@http://127.0.0.1:4000 /@http://127.0.0.1:8080

Customization

Option Description Default
locations service locations to proxy. None
-c / -config nginx config template file ./config/default.conf
--port listening port for the reverse proxy 5000
--verbose enable verbose output False
--sync force synchronous communication with the proxy False
--tag docker tag for the reverse proxy container dev/cors-reverse-proxy
--dockerfile dockerfile for building the container ./Dockerfile

Under the hood, configuration options are applied to the --config template file and rendered using jinja2. If you wish, you can pass additional arguments and use them in the config template. Example:

proxybootstrap \
    -my_var1 Test1 \
    --my_var2 Test2 \
    --port 5000 \
    /@http://127.0.0.1:8080

can be accessed in a template with

{{ my_var1 }}
{{ my_var2 }}

Alternatives

  • Write a custom proxy configuration for nginx or other proxy servers like trafik, envoy or haproxy
  • When using webpack or another popular tool there might be some plugins like devserver-proxy for vuejs
  • Mess around with headers to allow specific CORS requests

Development

If you do not have pipx and pipenv, install with

python3 -m pip install --user pipx
python3 -m pipx ensurepath
pipx install pipenv

Install all dependencies with

pipenv install --dev

To format, sort imports and check PEP8 conformity, run

pipenv run black .
pipenv run isort
pipenv run flake8

(These are also configured as a git pre commit hook)

Notice

This configuration is very minimal and intended for development use only.

proxybootstrap's People

Contributors

romnn avatar

Stargazers

 avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.