Skip to content

Commit

Permalink
fix: add diagnostics to node server
Browse files Browse the repository at this point in the history
  • Loading branch information
kitsonk committed Jun 6, 2024
1 parent c5b1819 commit 0a8aa42
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 2 deletions.
2 changes: 1 addition & 1 deletion deno.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@oak/acorn",
"version": "0.6.0-alpha.2",
"version": "0.6.0-alpha.3",
"exports": {
".": "./mod.ts",
"./context": "./context.ts",
Expand Down
7 changes: 6 additions & 1 deletion http_server_node.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,10 +37,12 @@ class RequestEvent implements _RequestEvent {
}

get request(): Request {
console.log("read request");
return this.#request;
}

get response(): Promise<Response> {
console.log("read response");
return this.#promise;
}

Expand Down Expand Up @@ -87,10 +89,12 @@ class RequestEvent implements _RequestEvent {

// deno-lint-ignore no-explicit-any
error(reason?: any): void {
console.log("error", reason);
this.#reject(reason);
}

async respond(response: Response | PromiseLike<Response>): Promise<void> {
console.log("respond", response);
if (this.#resolved) {
throw new Error("Request already responded to.");
}
Expand Down Expand Up @@ -188,6 +192,7 @@ export default class HttpServer implements Server {
start: (controller) => {
this.#controller = controller;
const server = this.#server = createServer((req, res) => {
console.log("incoming", req, res);
controller.enqueue(
new RequestEvent(req, res, this.#host, this.#address),
);
Expand Down Expand Up @@ -222,7 +227,7 @@ export default class HttpServer implements Server {

[Symbol.asyncIterator](): AsyncIterableIterator<RequestEvent> {
if (!this.#stream) {
throw new TypeError("Serer hasn't started listening.");
throw new TypeError("Server hasn't started listening.");
}
return this.#stream[Symbol.asyncIterator]();
}
Expand Down

0 comments on commit 0a8aa42

Please sign in to comment.