htagweb
This "htagweb" module provides two htag's "runners":
- WebServer : for http only exchanges
- WebServerWS : for http/ws exchanges (first rendering is on http)
Theses runners are a lot more complete than the defaults ones (WebHTTP & WebWS, provided nativly with htag) If you want to expose your HTag apps on the web : they are the only real/official solutions. Theses are a lot robust and IRL tested.
- based on starlette
- compatible with uvloop !!!
- compatible with multiple gunicorn webworkers !!!
- works on gnu/linux or windows !
- Each user has its own process (for session, and htag app)
- real starlette session available (in htag instance, and starlette request)
- compatible with oauth2 authent ( authlib )
- real process managments (interactions timeout, process expirations, ...)
- NOT READY YET parano mode (can aes encrypt all communications between client & server ... to avoid mitm'proxies)
But be aware : it's production ready (at least, for me). It may not be free of bugs or security holes: USE AT YOUR OWN RISK. Htag and this module are youngs, and not widely tested (by experts/hackers). But due to the nature of htag, and theses runners, the risk may be minimal (only DoS), stealing datas may not be possible.
The concepts are the same :
- one user can run only one instance of an htag app at one time (like in desktop mode).
- All user processes are destroyed, after an inactivity timeout (not like in desktop mode, to preserve healthy of the webserver)
- the "session" live as long as the server live (may not be a problem on many hosting service (where they shutdown the server after inactivities))
architecture
Here is a rapid map ;-)
Roadmap / futur
- ? replace starlette by fastapi ?
- better logging !!!!
- more parameters (session size, etc ...)
- parano mode
- perhaps a bi-modal version (use ws, and fallback to http when ws com error)
Examples
A "hello world" could be :
from htag import Tag
class App(Tag.div):
def init(self):
self+= "hello world"
from htagweb import WebServer # or WebServerWS
WebServer( App ).run()
or, with gunicorn (in a server.py
file):
from htag import Tag
class App(Tag.div):
def init(self):
self+= "hello world"
from htagweb import WebServer # or WebServerWS
app=WebServer( App )
and run server :
gunicorn -w 4 -k uvicorn.workers.UvicornH11Worker -b localhost:8000 --preload server:app
See a more advanced example in examples folder
python3 examples/main.py
htagweb.HtagServer
This is a new beast, which is available in this module, and it's COMPLETLY different from ALL others htag runners. See it like an "htag server", very useful during development phase. In console, type :
$ python3 -m htagweb
It will run a solid http/ws, with all htag/web features, and you can browse htag's apps in an html page.
It's not the official way to expose htag's apps on the web. But I'm currently exploring that (because it's a lot lot simpler ;-)