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

0.0.10 • 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.

Readme

Keywords

none

Package Sidebar

Install

npm i deno-http-worker

Weekly Downloads

274

Version

0.0.10

License

MIT

Unpacked Size

98.1 kB

Total Files

29

Last publish

Collaborators

  • maxmcd