Opensource implemention of Stackblitz and CodeSandBox's serviceworker-based tunneling strategy.
npm install weblocalOpen source implemention of StackBlitz and CodeSandBox's ServiceWorker-based loopback emulator (iframe only).
Simple web server | Hono in browser
javascript
// From Client JavaScript!import { serve } from "weblocal";
const server = await serve(() => new Response("
Hello!
", { headers: { "Content-Type": "text/html" } }));previewFrame.src = server.url // directly put into in-context iframe
`$3
`javascript
import { Hono } from "hono";
import { serve } from "weblocal";const app = new Hono();
app.get("/", c => c.text("Hello Hono!"));
const server = await serve(app.fetch);
`Usage
`sh
npm i weblocal
``To run user-defined documents in an HTTPS environment, leading online IDEs StackBlitz and CodeSandBox have incorporated a “bypass” system into their own services using ServiceWorker and MessageChannel.
This technique is memory efficient and has less overhead than using Object URLs. Despite its convenience, due to the competitive nature of the online IDE market, companies are keeping their sources private.
So, as an individual web developer, I reinvented the wheel as an open source low-level implementation, using CloudFlare's stunning CDN and edge computing system.
WebLocal is MIT licensed.