Public folder from create-t3-app trpc router?
My google-fu is failing me! Can I access the content in the public folder from the API? I tried referencing it the way I would on the frontend ("/images/file/path.svg") and it doesn't seem to be able to see the files.
I know I could append the domain, but I would like to access the files directly rather than over http.
12 Replies
You can't as when on the server, it doesn't know the url of itself? If that makes sense.
So you have to find out the url of your site and prefix the path with it.
Like:
On client side, the js has access to your domain, let's just say https://example.vercel.com and therefore doing
/lol
automatically points to https://example.vercel.com/lol
On the server side, it does not have access to https://example.vercel.com and doesn't work like expectedI was hoping the public folder would still be available through some direct file pathing, but I guess the whole point is that they're not part of the source package.
It would be almost impossible to know the path to that folder since you don't own it (the server) assuming you're using Vercel
Also assuming they're even in the same "local system"
Guessing I could add something to the bundler to pull them into a src folder or I can maintain a duplicate copy of them internally.
Or setup your own cdn
I have image files that I need to use in the router and don't want to deal with the bandwidth or time for downloading them each request.
Mostly a timing thing since I only have 10seconds of processing time before it hits the timeout wall.
maybe u can do something like whats mentioned on the trpc docs to get ur base url
Usage with Next.js | tRPC
Next.js makes it easy for you to build your client and server together in one codebase. tRPC makes it easy to share types between them, ensuring typesafety for your application's data fetching.
I definitely could. I just need to find the best way to access them directly instead of via http.
Can't that way.
Appears to be working, will test on vercel and report back.
Confirmed. Works on Vercel prod as well.
Unknown User•2y ago
Message Not Public
Sign In & Join Server To View