Skip to content

Commit

Permalink
fix request.signal
Browse files Browse the repository at this point in the history
  • Loading branch information
penx committed Jan 25, 2023
1 parent 1158276 commit e1d896f
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 7 deletions.
7 changes: 5 additions & 2 deletions __tests__/server-test.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import supertest from "supertest";
import { createRequest } from "node-mocks-http";
import { createRequest, createResponse } from "node-mocks-http";
import {
createRequestHandler as createRemixRequestHandler,
Response as NodeResponse,
Expand Down Expand Up @@ -237,7 +237,10 @@ describe("google-cloud-functions createRemixRequest", () => {
},
});

expect(createRemixRequest(expressRequest)).toMatchInlineSnapshot(`
let expressResponse = createResponse();

expect(createRemixRequest(expressRequest, expressResponse))
.toMatchInlineSnapshot(`
NodeRequest {
"agent": undefined,
"compress": true,
Expand Down
11 changes: 6 additions & 5 deletions server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ export function createRequestHandler({

return async (req: GcfRequest, res: GcfResponse) => {
try {
let request = createRemixRequest(req);
let request = createRemixRequest(req, res);
let loadContext =
typeof getLoadContext === "function"
? getLoadContext(req, res)
Expand Down Expand Up @@ -90,15 +90,16 @@ export function createRemixHeaders(
return headers;
}

export function createRemixRequest(req: GcfRequest): NodeRequest {
export function createRemixRequest(
req: GcfRequest,
res: GcfResponse
): NodeRequest {
let origin = `${req.protocol}://${req.get("host")}`;
let url = new URL(req.url, origin);

let controller = new AbortController();

req.on("close", () => {
controller.abort();
});
res.on("close", () => controller.abort());

let init: NodeRequestInit = {
method: req.method,
Expand Down

0 comments on commit e1d896f

Please sign in to comment.