deno-http-worker
TypeScript icon, indicating that this package has built-in type declarations

0.0.12 • Public • Published

deno-http-worker

NPM version

Similarly to deno-vm, deno-http-worker lets you securely spawn Deno http servers.

Usage

import { newDenoHTTPWorker } from 'deno-http-worker';

let worker = await newDenoHTTPWorker(
    `export default {
        async fetch(req: Request): Promise<Response> {
            return Response.json({ ok: req.url });
        },
    }`,
    { printOutput: true, runFlags: ["--alow-net"] }
);

const body = await new Primise((resolve, reject) => {
    const req = worker.request("https://hello/world?query=param", {}, (resp) => {
        const body: any[] = [];
        resp.on("error", reject);
        resp.on("data", (chunk) => {
            body.push(chunk);
        });
        resp.on("end", () => {
            resolve(Buffer.concat(body).toString());
        });
        console.log(resp)
    }
    req.end();
})
console.log(body) // => {"ok":"https://hello/world?query=param"}

worker.terminate();

Internals

Deno-http-worker connects to the Deno process over a Unix socket to make requests. As a result, the worker does not provide an address or url, but instead returns request function that calls http.request under the hood, but modifies the request attributes to work over the socket.

If you need more advanced usage here, or run into bugs, please open an issue.

Dependencies (0)

    Dev Dependencies (3)

    Package Sidebar

    Install

    npm i deno-http-worker

    Weekly Downloads

    23

    Version

    0.0.12

    License

    MIT

    Unpacked Size

    97.5 kB

    Total Files

    25

    Last publish

    Collaborators

    • maxmcd