Frontend developers often face with case, where they should use remote API development server. And if it uses https protocol and some sort cookie-based authorization and/or CORS, you should run https dev environment, that not so often easy to run.
Special case - development under Windows with Docker... It's some sort of BDSM :) And it's a right decision to use remote API in that case.
Having faced these problems more than once, I've made an image and compose for frontend developers that make it easy to proxy a remote backend locally.
Things you need to use the software and how to install them.
- docker
- docker-compose (or docker with compose plugin)
- OR NodeJS 16+
npx dev-backend-proxy -t https://jsonplaceholder.typicode.com -r https://jsonplaceholder.typicode.com -p 3001
-
Clone repo
-
Copy .env.example to .env
cp .env.example .env
-
Build and run docker-compose or use NodeJS
docker-compose up -d --build
Or with NodeJS
npm install & npm run start
-
Open http://localhost:3001/todos/ and see response from https://jsonplaceholder.typicode.com/todos/
-
Replace environments for your purposes and repeat step 2
Env | Description |
---|---|
PROXY_TO | Target |
HOST_PORT | Where service should listen |
REPLACED_ORIGIN | What origin we should use to replace Origin header |
- PROFIT!
Distributed under the MIT License.