Need a publicly accessible reverse proxy? Want to skip testing with localhost? Blackbird has an easy solution.
Blackbird API Development
Setting up the Proxy
First let’s configure a simple reverse proxy with nginx using the following nginx.conf:
server {
listen 80;
location / {
proxy_pass "https://httpbin.org/";
}
}
All requests sent to this server will proxy out to httpbin.org — a nice tool for developing and testing this proxy with downstream servers/APIs.
Next, we’ll define a simple Dockerfile that uses our ngnix configuration to build an image:
`
FROM nginx:latest
COPY nginx.conf /etc/nginx/conf.d/default.conf`
EXPOSE 80
Hosting the Proxy with Blackbird
After installing the Blackbird CLI, we can publicly host this reverse proxy with a Blackbird deployment:
blackbird deployment create proxy -d Dockerfile -c .
✔ input validated
✔ environment is ready
✔ no matching mock instance found
✔ image successfully built
✔ image successfully pushed
✔ checking existing deployments
✔ creating application for deployment
✔ application deployment created
+-------+------------+----------+---------------------------------------------------------+
| NAME | TYPE | STATUS | URL |
+-------+------------+----------+---------------------------------------------------------+
| proxy | deployment | Ready | https://matts-org-a0696.blackbird-relay.a8r.io/proxy/ |
+-------+------------+----------+---------------------------------------------------------+
Blackbird gave us a public host that is running our reverse proxy in a container - let’s try it out:
curl --request POST -d '{"message":"hello"}' \
https://matts-org-a0696.blackbird-relay.a8r.io/proxy/post
{
"args": {},
"data": "{\"message\":\"hello\"}",
"files": {},
"form": {},
"headers": {
"Accept": "*/*",
"Content-Length": "19",
"Content-Type": "application/json",
"Host": "httpbin.org",
"User-Agent": "curl/8.6.0"
},
"json": {
"message": "hello"
},
"url": "https://httpbin.org/post"
}
Just like that, our reverse proxy is live and hosted 🚀
Happy proxying!
Top comments (0)