livelocalhost
Advanced tools
+10
-5
@@ -75,3 +75,3 @@ // LiveLocalhost class | ||
| // start HTTP server | ||
| http.createServer(async (req, res) => { | ||
| http.createServer({ keepAliveTimeout: 0 }, async (req, res) => { | ||
@@ -91,6 +91,8 @@ // get requested path | ||
| const useragent = res?.req?.headers?.['user-agent']?.replace(/.+\)\s/, '') || 'unknown browser'; | ||
| res.writeHead(200, { | ||
| 'Content-Type': 'text/event-stream', | ||
| 'Cache-Control': 'no-cache', | ||
| 'Connection': 'keep-alive' | ||
| 'Connection': 'keep-alive', | ||
| }); | ||
@@ -100,6 +102,9 @@ | ||
| this.#resSet.add(res); | ||
| if (this.accessLog) concol.log(styleText('yellow', `SSE connection opened: ${ useragent }`)); | ||
| // close connection | ||
| res.on('close', () => { | ||
| req.on('close', () => { | ||
| this.#resSet.delete(res); | ||
| if (this.accessLog) concol.log(styleText('yellow', `SSE connection closed: ${ useragent }`)); | ||
| }); | ||
@@ -176,4 +181,4 @@ | ||
| 'Content-Type': mimeType.get(type) || mimeType.get('error'), | ||
| 'Content-Length': Buffer.byteLength(content), | ||
| 'Cache-Control': 'must-revalidate, max-age=0', | ||
| 'Content-Length': Buffer.byteLength(content) | ||
| }); | ||
@@ -185,3 +190,3 @@ res.write( content ); | ||
| }).listen( this.serveport ); | ||
| }).listen( this.serveport, '0.0.0.0' ); | ||
@@ -188,0 +193,0 @@ |
+5
-1
| // live reload client-side script for livelocalhost | ||
| /* global _hotloadJS_ */ | ||
| new EventSource('_reloadSSE_').addEventListener('change', e => { | ||
| const sse = new EventSource('_reloadSSE_'); | ||
| sse.addEventListener('change', e => { | ||
@@ -40,1 +41,4 @@ const | ||
| }); | ||
| // stop live reload | ||
| window.addEventListener('beforeunload', () => sse.close()); |
+1
-1
| { | ||
| "name": "livelocalhost", | ||
| "version": "1.2.6", | ||
| "version": "1.2.7", | ||
| "description": "localhost development server with live reloading", | ||
@@ -5,0 +5,0 @@ "type": "module", |
URL strings
Supply chain riskPackage contains fragments of external URLs or IP addresses, which the package may be accessing at runtime.
URL strings
Supply chain riskPackage contains fragments of external URLs or IP addresses, which the package may be accessing at runtime.
24977
1.83%462
1.32%