Skip to content

Commit

Permalink
Add readme, fix package.json and add deno.json to test dir
Browse files Browse the repository at this point in the history
  • Loading branch information
maxmcd committed May 8, 2024
1 parent fcd0d5d commit 445b24e
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 3 deletions.
29 changes: 29 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
# deno-http-worker

Similarly to [deno-vm](https://github.com/casual-simulation/node-deno-vm), deno-http-worker lets you securely spawn Deno http servers.

## Usage

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

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

let json = await worker.client
.get("https://hello/world?query=param")
.json();
console.log(json) // => { ok: 'https://hello/world?query=param' }

worker.terminate();
```

## Internals

When spawning the Deno process deno-http-worker connects to the process over a Unix socket. This is for performance and efficiency. As a result, the worker does not provide an address to make requests to, but instead returns an instance of a [got](https://www.npmjs.com/package/got) client that you can make requests with. This ensures that only the underlying `http2.ClientHttp2Session` is used to make requests.

If you need more advanced usage that cannot be covered by `got`, please open a ticket.
6 changes: 3 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
{
"name": "deno-http-worker",
"version": "0.0.0",
"version": "0.0.1",
"description": "",
"main": "dist/plugin.js",
"types": "./dist/plugin.d.ts",
"main": "dist/index.js",
"types": "./dist/index.d.ts",
"scripts": {
"test": "vitest run",
"test:watch": "vitest",
Expand Down
1 change: 1 addition & 0 deletions src/test/deno.json
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{ "lock": false }

0 comments on commit 445b24e

Please sign in to comment.