xpodev / seamless

A Python package for creating and manipulating HTML components. It is working similar to React.js, but in Python.
https://seamless.readthedocs.io
MIT License
11 stars 1 forks source link

Accessing the underlying socket.IO server #46

Closed binyamin555 closed 1 month ago

binyamin555 commented 2 months ago

I'm trying to access the socket io server so I can create my own events to be called from client side without having to bind it to some component.

I managed to get a reference to the server, but it's really ugly:

from fastapi import FastAPI
from seamless.middlewares import ASGIMiddleware as SeamlessMiddleware

app = FastAPI()

seamless_app = SeamlessMiddleware(app)

server = seamless_app.server

# using server here

if __name__ == "__main__":
    import uvicorn
    uvicorn.run(seamless_app, host="localhost", port=8000)

This is not so straight forward and it's not ideal, since now the SeamlessMiddleware now wraps FastAPI instead of FastAPI wrapping SeamlessMiddleware which is better (since FastAPI also handles errors nicely).

neriyaco commented 1 month ago

This is fixed with #33