SolidJSS
SolidJSโ€ข2y agoโ€ข
3 replies
Some Call Me Tim

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:
export function routeData(props: RouteDataArgs) {
  return createServerData$(async (_, { request }) => {
     // Snipped out the actual db call.
     // Gets the dynamic url from the db and redirect
     return redirect(dbResponse, 301);
  });
}

export default function generateEmbedThumb() {
  return null;
}


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!
Screenshot_2024-04-09_at_3.28.03_PM.webp
Was this page helpful?