Solid Start Route for simple redirect
I've got a Start route thats sole purpose is to generate a 301 redirect to a dynamic image url I make in createServerData.
It's working fine and it does redirect to the image, however if I curl -v I can see that I also get the <!DOCTYPE html><html lang="en" ><head ><title etc...; and my entire apps CSS also delivered, which is a 156kB!
This is basically it:
Ryan says "it is going to stick the page in the the HTML as it is going through Solid's rendering. I'd just make a server function outside of routing or maybe an API route.. the whole routeData stuff is setup is the reactive router.. client package basically. It wouldn't work a different way."
Sooo, while an API call does what I want, it has to prefix the path with /api (AFAIK?), and this url needs to be a path right off the root as it's replacing a current url which is embedded in loads of client websites. How does one make a server function outside of routing that responds when a route is hit?
i.e. mydomain.com/embedimage returning a 301 to an actual url of a jpg.
This is what I currently get when using a default route... 156k of html + css, then a redirect to the 11k image!
3 Replies
It does not need to be under
/api
. You can set any path you want.. it will be the same name as the file.If the html/css part is an issue, why not straight up use an api route?
Ex. src/routes/getRandom.ts
API Routes should run on the server afaik
derp, thanks both. Looks like a case of RTFM. I read an old thread that said /api was for api routes, then skimmed the api route handler example and it used /api as well. Didn't realize the magic was in the function name, not the file location.