Proxy Pass REST API with HTTPS support #3543
the3dsandwich
started this conversation in
Show and tell
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
Originally drafted as a question, but after some testing I found out NPM already supports what I want to do. So I share what I did.
Problem Overview
I want to proxy an HTTP API through NPM, and use NPM to manage ssl certificates so I can expose it as an HTTPS API.
In my head I want it to be:
I know backend API works, so I want to ask how I can approach setting up NPM to take HTTPS requests and convert to HTTP.
Also, HTTP/HTTPS methods will need to support POST as well, not just GETs
Why
I was trying to develop a client-server webapp hosted over GitHub pages (
https://<something>.github.io/<something_else>
). Backend server (API) is selfhosted, currently exposes as something likehttp://<domain.com>:<port>/<something_else>
. I can cURL the API just fine, but when I access it through the hosted instance of the frontend, it showed error like the following:Mixed Content: The page at 'https://<something>.github.io/<something_else>' was loaded over HTTPS, but requested an insecure resource 'http://<domain.com>:<port>/<something_else>'. This request has been blocked; the content must be served over HTTPS.
As I have a working instance of NPM with an existing SSL certificate, I have two apparent choices:
I figured reverse proxy-ing APIs will enable me to make more prototypes in the future faster, and is more fun.
How to do
Just add a proxy host. I did mine with websocket support, HTTP/2 support but I suspect it might work with fewer features enabled. Screenshots below show config I used and that POST method API calls works.
Conclusion
That's all. Feel like a fool typing this essay out jsut to find out it works all along. But I hope this helps someone in the future trying similar things so I'll leave this here as is.
Beta Was this translation helpful? Give feedback.
All reactions