Skip to main content

No project description provided

Project description

litestar-browser-reload

PyPI - Version PyPI - Python Version


[!IMPORTANT] This plugin currently contains minimal features and is a work-in-progress

Auto browser reload plugin for litestar, intended for use in development.

Table of Contents

Installation

pip install litestar-browser-reload

Usage

from pathlib import Path

from litestar import Litestar
from litestar.contrib.jinja import JinjaTemplateEngine
from litestar.template.config import TemplateConfig
from litestar.response import Template
from litestar_browser_reload import BrowserReloadPlugin

templates_path = Path("templates")
browser_reload = BrowserReloadPlugin(watch_paths=(templates_path,))

app = Litestar(
    route_handlers=[],
    debug=True,
    plugins=[browser_reload],
    template_config=TemplateConfig(
        directory=templates_path,
        engine=JinjaTemplateEngine,
    ),
)
 <script>
    // Create a new WebSocket connection to the specified endpoint
    const socket = new WebSocket('ws://localhost:8000/browser-reload');

    // Event listener for when the WebSocket connection is opened
    socket.onopen = function(event) {
    console.log('WebSocket connection established', event);
    };

    // Event listener for when a message is received from the server
    socket.onmessage = function(event) {
    console.log('Message received from server', event.data);
    // Check if the received message is 'reload'
    if (event.data === 'reload') {
        console.log('Reloading page as instructed by server');
        // Reload the current page
        window.location.reload();
    }
    };

    // Event listener for when the WebSocket connection is closed
    socket.onclose = function(event) {
    console.log('WebSocket connection closed', event);
    };

    // Event listener for any errors that occur with the WebSocket connection
    socket.onerror = function(error) {
    console.log('WebSocket error', error);
    };
</script>

License

litestar-browser-reload is distributed under the terms of the MIT license.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

litestar_browser_reload-0.0.1.tar.gz (5.4 kB view hashes)

Uploaded Source

Built Distribution

litestar_browser_reload-0.0.1-py3-none-any.whl (4.4 kB view hashes)

Uploaded Python 3

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page