Closed sandeep-gh closed 2 years ago
JustPy requires a server that supports ASGI as it based on Starlette: https://www.starlette.io/
I have had success using Centos, pipenv, apache, and systemctl services. I'm willing to send you my configurations if you would like help getting a production environment setup, for example, here is the Apache config, just let me know what else you need:
<VirtualHost *:80>
ServerName whatever_your_server_name_is
ServerAlias whatever_your_ip_address_is
ProxyPreserveHost On
RewriteEngine On
RewriteRule ^(.*)$ https://whatever_your_ip_address_is$1 [R=301]
RewriteCond %{SERVER_NAME} =whatever_your_server_name_is [OR]
RewriteCond %{SERVER_NAME} =whatever_your_ip_address_is
RewriteRule ^ https://%{SERVER_NAME}%{REQUEST_URI} [END,NE,R=permanent]
</VirtualHost>
<VirtualHost *:443>
ServerAdmin webmaster@yourdomain.com
ServerName whatever_your_server_name_is
ServerAlias whatever_your_ip_address_is
DocumentRoot /var/www/html
SSLEngine on
ProxyPreserveHost On
RequestHeader set X-Forwarded-Proto https
RewriteEngine on
RewriteCond %{HTTP:CONNECTION} ^Upgrade$ [NC]
RewriteCond %{HTTP:Upgrade} =websocket
RewriteRule /(.*) ws://127.0.0.1:8000/$1 [P,QSA,L]
RewriteCond %{HTTP:Upgrade} !=websocket
RewriteRule /(.*) http://127.0.0.1:8000/$1 [P,QSA,L]
ErrorLog /var/log/httpd/error.log
CustomLog /var/log/httpd/access.log combined
SSLCertificateFile /usr/local/public.crt
SSLCertificateKeyFile /usr/local/private.key
SSLCertificateChainFile /usr/local/intermediate.crt
</VirtualHost>
Spend fair part of the day figuring out the various web deployment stacks. Long story short, i think if I can make Starlette app run in the same context as shown in this SO answer then I think I plug this in uWSGI framework. Otherwise i have to give up on httpd/uwsgi stack and move to nginx+gunicorn which is not preferred.
The key part of that SO answer is
app = web.Application()
app.add_routes([web.get('/', handle),
web.get('/{name}', handle)])
runner = web.AppRunner(app)
await runner.setup()
sock = mk_socket(host, port, reuseport=reuseport)
srv = web.SockSite(runner, sock)
await srv.start()
For the web.Application
there is web.AppRunner
which is bound to a socket by web.SockSite
. I am not sure how to do the same/equivalent for Starlette app. All Starlette app is run via uvicorn which itself creates a socket on the host+port. I need something that can bind to existing socket.
There are too many web deployment framework and I am bit confused about which to use and which one is suitable. For various reasons, I settled on httpd(OpenBSD) and uWSGI. I tried uWSGI (with gevent support) but it seems to be not compatible with justpy. I get error
Is it possible to deploy justpy using uWSGI. It does seem to have async support. Is the use of uvicorn necessary? My understanding in web deployment is bit limited, so any pointers, suggestions, clarification would be great.
Thanks -S