Learn how to build a simple Node.js proxy server that forwards HTTP requests. Explore editable, runnable code via web containers to inspect headers and relay responses seamlessly.
notes:
this demo version uses webcontainers to run the code, the webcontainer runtime is limited in that at the time of writing
it is not handling https correctly. Therefore the demonstration code uses http. The same logic applies for https,
the call would typically require some modification either with {ca:cert} to supply the
signing certificate the server responds with, or with {rejectUnauthorized:false} to allow
self-signed certificates
generate https certificate ext-code.com
i typically use this code for when say an esp32 is not communicating properly with the internet, i can proxy the esp32 request through a server like this. maybe the esp32 network stack is not working 100% or something. i think theoretically the host file could be modified for a domain such as example.com to point to the proxy server, then in the proxy server rewrite the host header and forward the request via the ip address of the server you want to contact this is untested at the moment, maybe i'll patch the fetch command to simulate the host file and include the deomstration code at some point
a working version of the nodejs https proxy server will be available /code/nodejs/servers/very-simple-proxy.nodejs.js ext-code.com