I'm building a local web interface for an over-engineered desk fan. The page has two buttons and a slider, and the browser-side controls are already working. Now I need to send the slider's current value from JavaScript to a Python script that controls the fan motor. The page is currently being served as static content by Nginx in a container. What's the right way to connect the browser code and the Python process? Is this an inter-process communication problem, or should I use another approach?
1 Answer
The usual solution is to run a small Python web server alongside the static page. Have the JavaScript call an endpoint on that server with fetch(), sending the slider value whenever it changes or when the user releases the slider. The Python handler can validate the value and pass it to the motor-control code. You don’t need to duplicate the webpage—the static Nginx server can continue serving the HTML, CSS, and JavaScript while the Python service acts as a separate API.

So the browser would keep loading the page from Nginx, but send the control values to a separate local Python endpoint? I was assuming the Python service would have to serve the same page too.