Skip to content

Commit

Permalink
fix(event): normalize event.path
Browse files Browse the repository at this point in the history
  • Loading branch information
pi0 committed May 15, 2023
1 parent aadec3d commit 981c89f
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 4 deletions.
9 changes: 7 additions & 2 deletions src/event/event.ts
@@ -1,6 +1,11 @@
import type { H3EventContext } from "../types";
import type { NodeIncomingMessage, NodeServerResponse } from "../node";
import { MIMES, sanitizeStatusCode, sanitizeStatusMessage } from "../utils";
import {
MIMES,
sanitizeStatusCode,
sanitizeStatusMessage,
getRequestPath,
} from "../utils";
import { H3Response } from "./response";

export interface NodeEventContext {
Expand All @@ -18,7 +23,7 @@ export class H3Event implements Pick<FetchEvent, "respondWith"> {
}

get path() {
return this.req.url;
return getRequestPath(this);
}

/** @deprecated Please use `event.node.req` instead. **/
Expand Down
4 changes: 2 additions & 2 deletions src/utils/request.ts
Expand Up @@ -113,8 +113,8 @@ export function getRequestProtocol(

const DOUBLE_SLASH_RE = /[/\\]{2,}/g;

export function getRequestPath(event: H3Event) {
const path = (event.path || "/").replace(DOUBLE_SLASH_RE, "/");
export function getRequestPath(event: H3Event): string {
const path = (event.node.req.url || "/").replace(DOUBLE_SLASH_RE, "/");
return path;
}

Expand Down

0 comments on commit 981c89f

Please sign in to comment.