@openziti/ziti-browzer-sw
Version:
Service Worker used as part of the OpenZiti browZer stack
105 lines (69 loc) • 3.55 kB
Markdown
<p align="center" width="100%">
<a href="https://ziti.dev"><img src="ziti.png" width="100"></a>
</p>
<p align="center">
<b>
<a>@openziti/ziti-browzer-sw</a>
<br>
<br>
<b>
This component contains the ServiceWorker used as part of the <a href="https://ziti.dev/about">OpenZiti</a> Zero Trust browZer stack</b>
</p>
<p align="center">
<br>
<b>Are you interested in knowing how to easily embed programmable, high performance, zero trust networking into your app, on any internet connection, without VPNs?
<br>
Learn more about our <a href="https://ziti.dev/about">OpenZiti</a> project by clicking the image below:</b>
<br>
<br>
<a href="https://ziti.dev"><img src="ziti-dev-logo.png" width="200"></a>
</p>
---
[]()
[]()
[]()
[](https://opensource.org/licenses/Apache-2.0)
[]()
[](CONTRIBUTING.md)
[](CODE_OF_CONDUCT.md)
---
<!-- TOC -->
- [Overview](
- [Installation](
- [Contributing](
- [License](
<!-- /TOC -->
coming soon...
The `ziti-browzer-sw` is intended to be consumed by the [`ziti-http-agent`](https://github.com/openziti/ziti-http-agent), not as a general purpose module in your build. It is available through [npm](https://www.npmjs.com/package/@openziti/ziti-browzer-sw), and installed via the following command:
npm i @openziti/ziti-browzer-sw
The the [`ziti-http-agent`](https://github.com/openziti/ziti-http-agent) serves the contents of `ziti-browzer-sw` in response to HTTP requests originating from the
[`ziti-browzer-runtime`](https://github.com/openziti/ziti-browzer-runtime). It does so by using the code shown below:
```js
// 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;
}
```
[]()
Your Contributions are welcome! Please see our [Contributing Guide](Contributing.md) for more details. Thanks to all our contributors!
[]()
Apache 2.0