reactpy icon indicating copy to clipboard operation
reactpy copied to clipboard

ReactPy ASGI Middleware and standalone ReactPy ASGI App

Open Archmonger opened this issue 2 years ago • 4 comments
trafficstars

Issues

  • fix #1110

Solution

Create a ReactPy ASGI application that can also function as middleware.

Features of the ASGI application/middleware

  • Gain compatibility with every ASGI framework.
  • Allows ReactPy to be "self contained" if needed (run within any ASGI webserver without a backend).
  • Allows ReactPy to auto-serve web modules.

Things to deprecate:

  • reactpy.backend.*.configure is no longer needed.

Checklist

  • [ ] Tests have been included for all bug fixes or added functionality.
  • [ ] The changelog.rst has been updated with any significant changes.

Archmonger avatar Jul 18 '23 05:07 Archmonger

The more I develop this, the more I realize it's unwise to finish this PR until the following issues are closed

  • #1079
  • #653

This PR is in a 90% finished state, but I will hold off on finishing it for now and refocus on template tags.

Archmonger avatar Jul 18 '23 09:07 Archmonger

@rmorshea I will implement things using starlette for static files now, but ideally I don't want a web framework to be a dependency for us.

I would feel more comfortable using whitenoise as it's a static-file focused library that doesn't have extra stuff. However, this relies on this PR getting merged:

  • https://github.com/evansd/whitenoise/pull/359

Archmonger avatar Jul 20 '23 05:07 Archmonger

Note to self: It seems logical to mandate that ReactPy standalone's root component must be a html.html node. By forcing the user to template the whole page, this would eliminate the need for a janky Options(head=...) parameter.

html.html(
    {"lang": "en"},
    html.head(
        ...,
    ),
    html.body(
        ...,
    ),
)

It also seems logical to have ReactPyStandalone and ReactPyMiddleware to be discrete classes.

Archmonger avatar Aug 27 '23 03:08 Archmonger

The whitenoise maintainers have largely been MIA, so I went ahead and forked it into my own package ServeStatic.

This PR is no longer blocked.

Archmonger avatar Jul 11 '24 00:07 Archmonger