Skip to content
This repository has been archived by the owner on Jun 13, 2024. It is now read-only.

Commit

Permalink
fix: start proxy in cjs (#22)
Browse files Browse the repository at this point in the history
  • Loading branch information
fubhy committed Apr 29, 2023
1 parent 5848df9 commit f03b3ec
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 3 deletions.
5 changes: 5 additions & 0 deletions .changeset/moody-zebras-change.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@viem/anvil": patch
---

Fixed import from `http-proxy` package in cjs environments.
25 changes: 24 additions & 1 deletion examples/example-node/index.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import assert from "node:assert";
import { test } from "node:test";
import { createAnvil, getVersion } from "@viem/anvil";
import { createAnvil, createPool, getVersion, startProxy } from "@viem/anvil";

test("can fetch the anvil version", async () => {
const version = await getVersion();
Expand All @@ -21,3 +21,26 @@ test("can start and stop anvil instances", async () => {
await anvil.stop();
assert((anvil.status as string) === "idle");
});

test("can start and stop pool instances", async () => {
const pool = createPool();

const a = await pool.start(1);
assert(a !== undefined);
assert(a.status === "listening");

const b = await pool.start(123);
assert(b !== undefined);
assert(b.status === "listening");

await a.stop();
assert((a.status as string) === "idle");

await b.stop();
assert((b.status as string) === "idle");
});

test("can start and stop an anvil proxy", async () => {
const stop = await startProxy();
await stop();
});
4 changes: 2 additions & 2 deletions packages/anvil.js/src/proxy/createProxy.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import httpProxy from "http-proxy";
import { createProxyServer } from "http-proxy";
import { IncomingMessage, ServerResponse, createServer } from "node:http";
import { parseRequest, type InstanceRequestContext } from "./parseRequest.js";
import { type Pool } from "../pool/createPool.js";
Expand Down Expand Up @@ -77,7 +77,7 @@ export type CreateProxyOptions = {
* ```
*/
export function createProxy({ pool, options, fallback }: CreateProxyOptions) {
const proxy = httpProxy.createProxyServer({
const proxy = createProxyServer({
ignorePath: true,
ws: true,
});
Expand Down

0 comments on commit f03b3ec

Please sign in to comment.