BundleProtocol
Protocol handler for serving files from bundle sources.
Protocol handler for serving files from bundle sources.
Serves web resources from .wvb bundle files, supporting:
- GET and HEAD HTTP methods
- HTTP Range requests for streaming
- Content-Type and custom HTTP headers
Constructor
new BundleProtocol(source: Source, options?: BundleProtocolOptions | null);Prop
Type
Methods
Prop
Type
Examples
const source = new Source({
builtinDir: './bundles/builtin',
remoteDir: './bundles/remote',
});
const protocol = new BundleProtocol(source);
// Handle a request
const response = await protocol.handle('get', 'bundle://app/index.html');
console.log(`Status: ${response.status}`);
console.log(`Content-Type: ${response.headers['content-type']}`);constructor
const source = new Source({
builtinDir: './bundles',
remoteDir: './remote',
});
const protocol = new BundleProtocol(source);// `https://cdn.example.com/my-app/about` -> "/about/index.html" of the "my-app" bundle
const protocol = new BundleProtocol(source, {
bundleResolver: { type: 'pathname' },
});// Entry checksum verification is inherited from the source's read options; to serve
// without checking entry checksums, configure it on the source instead.
const source = new Source({
builtinDir: './bundles',
remoteDir: './remote',
options: { dataRead: { checksum: { verify: false } } },
});
const protocol = new BundleProtocol(source);handle
// GET request
const response = await protocol.handle('get', 'bundle://app/index.html');
if (response.status === 200) {
console.log(response.body.toString('utf-8'));
}// Range request for streaming
const response = await protocol.handle('get', 'bundle://app/video.mp4', { Range: 'bytes=0-1023' });
console.log(`Status: ${response.status}`); // 206 Partial Content