From 405fee2676a9cd81da8aadeba7da1840e8a265cb Mon Sep 17 00:00:00 2001 From: Luke Edwards Date: Thu, 11 Mar 2021 13:12:45 -0800 Subject: [PATCH] fix(request): add `hostname` property; - Related #3 --- index.d.ts | 1 + src/utils.js | 6 +++--- types/index.test-d.ts | 3 ++- 3 files changed, 6 insertions(+), 4 deletions(-) diff --git a/index.d.ts b/index.d.ts index cda3fca..8f2d6b1 100644 --- a/index.d.ts +++ b/index.d.ts @@ -23,6 +23,7 @@ export interface ServerRequest { url: string; method: string; path: string; + hostname: string; params: Params; query: URLSearchParams; search: string; diff --git a/src/utils.js b/src/utils.js index 5e9334c..fa334a8 100644 --- a/src/utils.js +++ b/src/utils.js @@ -33,12 +33,12 @@ */ export function request(event) { const { request, waitUntil } = event; - const { url, method, headers } = request; + const { url, method, headers } = request; // todo: cf + const { hostname, pathname, search, searchParams } = new URL(url); const ctype = headers.get('content-type'); - const { pathname, search, searchParams } = new URL(url); return /** @type {ServerRequest} */ ({ url, method, headers, - path: pathname, + hostname, path: pathname, search, query: searchParams, body: body.bind(0, request, ctype), extend: waitUntil diff --git a/types/index.test-d.ts b/types/index.test-d.ts index 1d477d5..1f9e8e2 100644 --- a/types/index.test-d.ts +++ b/types/index.test-d.ts @@ -94,10 +94,11 @@ API.add('POST', '/items', async (req, res) => { tsd.expectType(res); // Assert `req` properties - tsd.expectType(req.method); tsd.expectType(req.url); tsd.expectType(req.path); tsd.expectType(req.params); + tsd.expectType(req.hostname); + tsd.expectType(req.method); tsd.expectType(req.query); tsd.expectType<()=>Promise>(req.body); tsd.expectType<(f:any)=>void>(req.extend);