What's a clean method to strip the handler from a route? #379
-
If the browser makes a request like {
name: "foo-handler",
type: "http",
base: "/foo",
handler: "./backend/foo-handler.ts",
} then how can i convert I want to avoid hardcoding a magic string or doing something similar. If there's a way to just get the string |
Beta Was this translation helpful? Give feedback.
Answered by
FunctionDJ
Sep 23, 2024
Replies: 1 comment
-
Findings:
// backend/foo-handler.ts
import { getRequestURL } from "vinxi/http"
import { routerBaseURL } from "vinxi/manifest"
export default eventHandler(async (event) => {
const url = getRequestURL(event)
const pathNameWithoutBase = path.relative(routerBaseURL, decodeURI(url.pathname))
// ...
} |
Beta Was this translation helpful? Give feedback.
0 replies
Answer selected by
FunctionDJ
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Findings:
event.path
seems to have the router part already removed, but includes search paramsevent.path
isn't a valid URL,new URL(event.path)
can't be used to separate the actual path from the search paramspath.relative(routerBaseURL, decodeURI(url.pathname))
seems like the cleanest solution for now