API w/o File Routes Component Possible?!
Are there any ways to create api routes w/o using the file routes component please? Like a way to specify a url path in the code and not via the file name please? Thanks!
3 Replies
You can create a catchall api route and forward requests to an in-code router like express or hono if you want
Brilliant! Thank you so much!
I tried [...404].ts w/ a
export function POST(event: APIEvent) {}
in it but the log did not work, i also tried /api/[api].ts
but that did not work either, how would you create a catch all, all for anything under /api please?
never mind user error /api/[...catch].ts works!I've never done it before but what I presume what was meant is that inside the route component you use
getRequestEvent()
to obtain the request after which you are on your own.
Keep in mind that getRequestEvent().nativeEvent
(identical to APIEvent.nativeEvent
) holds the original h3
event which you'll probably want to leverage.getRequestEvent - SolidDocs
Documentation for SolidJS, the signals-powered UI framework
Event Object - h3
Event object carries an incoming request and context.