No project description provided
Project description
litestar-browser-reload
[!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
Built Distribution
Close
Hashes for litestar_browser_reload-0.0.1.tar.gz
Algorithm | Hash digest | |
---|---|---|
SHA256 | 7538cc172ead556fddd0e5fe3d5acafdd1c6cf4cea7df3da0045d350003df333 |
|
MD5 | bbfb443844b22e0f20e0c36025ce7fdb |
|
BLAKE2b-256 | fcb8822e144aa690ea4c061b6b92a66a68668f4ecb8bf0baa354c22ab4f63292 |
Close
Hashes for litestar_browser_reload-0.0.1-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 10a784c74916608ca754282a7f705ac707117d8b6fbd6ed058c688e4834827d8 |
|
MD5 | c8128522a63ca915305ea4e729d0e383 |
|
BLAKE2b-256 | 5e6b3085ea969abd66d9f00dd239357686d0d13c7cd0a2d56f281e1297dcf93c |