Skip to content

Commit 981c89f

Browse files
committed
fix(event): normalize event.path
1 parent aadec3d commit 981c89f

File tree

2 files changed

+9
-4
lines changed

2 files changed

+9
-4
lines changed

src/event/event.ts

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,11 @@
11
import type { H3EventContext } from "../types";
22
import type { NodeIncomingMessage, NodeServerResponse } from "../node";
3-
import { MIMES, sanitizeStatusCode, sanitizeStatusMessage } from "../utils";
3+
import {
4+
MIMES,
5+
sanitizeStatusCode,
6+
sanitizeStatusMessage,
7+
getRequestPath,
8+
} from "../utils";
49
import { H3Response } from "./response";
510

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

2025
get path() {
21-
return this.req.url;
26+
return getRequestPath(this);
2227
}
2328

2429
/** @deprecated Please use `event.node.req` instead. **/

src/utils/request.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -113,8 +113,8 @@ export function getRequestProtocol(
113113

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

116-
export function getRequestPath(event: H3Event) {
117-
const path = (event.path || "/").replace(DOUBLE_SLASH_RE, "/");
116+
export function getRequestPath(event: H3Event): string {
117+
const path = (event.node.req.url || "/").replace(DOUBLE_SLASH_RE, "/");
118118
return path;
119119
}
120120

0 commit comments

Comments
 (0)