Skip to content

Commit

Permalink
fix(request): add hostname property;
Browse files Browse the repository at this point in the history
- Related #3
  • Loading branch information
lukeed committed Mar 11, 2021
1 parent da1b762 commit 405fee2
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 4 deletions.
1 change: 1 addition & 0 deletions index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ export interface ServerRequest {
url: string;
method: string;
path: string;
hostname: string;
params: Params;
query: URLSearchParams;
search: string;
Expand Down
6 changes: 3 additions & 3 deletions src/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
3 changes: 2 additions & 1 deletion types/index.test-d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -94,10 +94,11 @@ API.add('POST', '/items', async (req, res) => {
tsd.expectType<ServerResponse>(res);

// Assert `req` properties
tsd.expectType<string>(req.method);
tsd.expectType<string>(req.url);
tsd.expectType<string>(req.path);
tsd.expectType<object>(req.params);
tsd.expectType<string>(req.hostname);
tsd.expectType<string>(req.method);
tsd.expectType<URLSearchParams>(req.query);
tsd.expectType<()=>Promise<unknown>>(req.body);
tsd.expectType<(f:any)=>void>(req.extend);
Expand Down

0 comments on commit 405fee2

Please sign in to comment.