@openziti/ziti-browzer-sw
v0.70.0
Published
Service Worker used as part of the OpenZiti browZer stack
Downloads
415
Readme
Overview
coming soon...
Installation
The ziti-browzer-sw
is intended to be consumed by the ziti-http-agent
, not as a general purpose module in your build. It is available through npm, and installed via the following command:
npm i @openziti/ziti-browzer-sw
The the ziti-http-agent
serves the contents of ziti-browzer-sw
in response to HTTP requests originating from the
ziti-browzer-runtime
. It does so by using the code shown below:
// Locate the path to the ServiceWorker distro within the build of our running instance
let pathToZitiBrowzerSwModule = require.resolve('@openziti/ziti-browzer-sw');
pathToZitiBrowzerSwModule = pathToZitiBrowzerSwModule.substring(0, pathToZitiBrowzerSwModule.lastIndexOf('/'));
// Read the component off the disk
fs.readFile( path.join( pathToZitiBrowzerSwModule, outgoing.path.split("/").pop() ), (err, data) => {
if (err) { // If we can't read the file from disk
res.writeHead(500, { 'x-ziti-http-agent-err': err.message });
res.end('');
return;
} else { // Emit the Service Worker onto the wire
res.writeHead(200, {
'Content-Type': 'application/javascript',
'Service-Worker-Allowed': '/',
'x-ziti-http-agent-info': 'self-configured ziti service worker'
});
res.write(data); // the actual service worker code
res.end('\n');
return;
}
Contributing
Your Contributions are welcome! Please see our Contributing Guide for more details. Thanks to all our contributors!
License
Apache 2.0