#How to properly use Dynamic routes with server components

5 messages · Page 1 of 1 (latest)

topaz meteor
#

I'm trying to set up dynamic routes rendered on the server-side that query the assets of the application (in the public directory). However, there's a difference in behavior between on-demand dynamic routes and generated routes (with generateStaticParams). Apparently, querying the assets only works when it's a route generated at build time. I'd like to understand why it's happening

My context: I'm trying to generate blurred images to show as image loaders, which is why I need to access the files within the public directory.

Live example: https://nextjs-image-loading.vercel.app/ (the broken pages are the ones with on-demand in the URL)

Repository: https://github.com/dpnunez/nextjs-image-loading/tree/main

GitHub

Contribute to dpnunez/nextjs-image-loading development by creating an account on GitHub.

near ravenBOT
#

🔎 This post has been indexed in our web forum and will be seen by search engines so other users can find it outside Discord

🕵️ Your user profile is private by default and won't be visible to users outside Discord, if you want to be visible in the web forum you can add the "Public Profile" role in id:customize

✅ You can mark a message as the answer for your post with Right click -> Apps -> Mark Solution
(if you don't see the option, try refreshing Discord with Ctrl + R)

shy saddle
# topaz meteor I'm trying to set up dynamic routes rendered on the server-side that query the a...

you need to do this when you are deploying to serverless platform

 const buffer = await fs.readFile(`${process.cwd()}/${filePath}`)

https://vercel.com/guides/how-can-i-use-files-in-serverless-functions#examples-of-reading-files

and in the build process, next will copy the file inside public folder to a static folder in the output. Then, only the output folder will be uploaded to vercel

Learn how to import, read, and store files inside Vercel Functions.

#

I assume your site should work fine when you run the production build locally because the public folder is in your file system

topaz meteor
#

It works here! Thank's 🙂