Skip to content

What's a clean method to strip the handler from a route? #379

Closed Answered by FunctionDJ
FunctionDJ asked this question in Q&A
Discussion options

You must be logged in to vote

Findings:

  • event.path seems to have the router part already removed, but includes search params
  • since event.path isn't a valid URL, new URL(event.path) can't be used to separate the actual path from the search params
  • path.relative(routerBaseURL, decodeURI(url.pathname)) seems like the cleanest solution for now
// 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))
	// ...
}

Replies: 1 comment

Comment options

You must be logged in to vote
0 replies
Answer selected by FunctionDJ
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
1 participant