Open a raw text file on server code without exposing it as a public asset
Hi! I am using Nuxt 3 and I have a very specific use case where I would like to have in my repository a text file that I would like to open and manipulate on the server. I have made this work only on development by using some
fs
and path
tricks, but the file obviously doesn't get added to the peoduction bundle. Every suggestion I have found involves serving the file publicly, but I need this file to stay private. Is there a way to make all of this happen? Essentially I would need some kind of file system alias that points to the right place in development, includes the file so that the bundler knows to add that file to the bundle, and then point to the right place on the production build.1 Reply
Have you tried nitro plugin to send a file stream? https://nuxt.com/docs/guide/directory-structure/server#sending-streams
You could add a login cookie check here.
Nuxt
server/ · Nuxt Directory Structure
The server/ directory is used to register API and server handlers to your application.