I have an extremely simple flask app that works perfectly with gunicorn and nginx over https with a domain. This shows me that all other configurations are working (IP, ports, https, etc.), but when I try and use it with the justpy library, which uses uvicorn, there is no interaction. The strange thing is that when I run it over the public ip of the GCP with the open port, it works just fine, so I am assuming it is a problem with my configuration of nginx.
The configuration and examples are below, along with the documentation I could find on this. This is running on a GCP VM instance, (e2 micro) with Ubuntu 21.04 installed. The public IP has been made static and I am using letsencrypt for HTTPS with the domain.
This might just be because the justpy library is so new, but I wanted to make sure it was not because of configuring nginx incorrectly.
So, using the simple flask app:
from flask import Flask
app = Flask(__name__)
@app.route('/')
def hello_world():
return 'Hello World from flaskapp 1!'
We get what we wanted when we go to https://test1.domain.com (test1.domain.com being just an example) which is "Hello World from flaskapp 1!" using the command
gunicorn fl1:app -b 0.0.0.0:5000
and using the following nginx config:
server {
listen 80;
listen 443 ssl http2;
server_name test1.domain.com;
ssl_certificate /etc/letsencrypt/live/domain.com/fullchain.pem;
ssl_certificate_key /etc/letsencrypt/live/domain.com/privkey.pem;
ssl_protocols TLSv1.3;
location / {
include proxy_params;
proxy_pass http://0.0.0.0:5000;
}
}
As well, if we use the code for justpy (which comes directly from their documentation here, and here) this also gives us what we want without any errors if I run it over the public IP with the open port and using a slight modification to the gunicorn command above:
gunicorn -k uvicorn.workers.UvicornWorker fl1:app -b 0.0.0.0:5000
import justpy as jp
app = jp.app
def my_click(self, msg):
self.text = 'I was clicked'
self.set_class('bg-blue-500')
def my_mouseenter(self, msg):
self.text = 'Mouse entered'
self.set_class('bg-red-500')
def my_mouseleave(self, msg):
self.text = 'Mouse left'
self.set_class('bg-teal-500')
def event_demo():
wp = jp.WebPage()
d = jp.Div(text='Not clicked yet', a=wp, classes='w-64 text-2xl m-2 p-2 bg-blue-500 text-white',
click=my_click, mouseenter=my_mouseenter, mouseleave=my_mouseleave)
return wp
jp.justpy(
event_demo,
start_server=False
)
This will give us a box that turns red with "Mouse entered" when the mouse is inside the box, green with "Mouse left" when the mouse is not in the box, and blue with "I was clicked" when we click on the box.
All that works, but, when I start using nginx (with the config above) to use https and the domain, that is when it starts to fail and the app constantly says "Page needs to be reloaded, click OK to reload" and it just keeps on reloading each time you click on OK. I suppose it has to do with the nginx config with uvicorn, but I have yet to figure it out.
The uvicorn documentation does not help much, and justpy has something in its main.html file for websockets from line 65, but I don't know how that would affect nginx. Any help would be appreciated.