I'm a beginner, so please don't judge me.
The solution is to serve your static files from the proper folder. In Nuxt, any file you want to be served as-is should be placed in the static folder (in Nuxt 3 you’d use the public folder). Files in these folders are copied directly to the root of your built site. For example, if you place hello_world.txt
in the static folder, it will be accessible at http://yourdomain.com/hello_world.txt
.
In your code, you’re trying to fetch from /server/static/hello_world.txt
, which isn’t recognized by Nuxt as a static asset directory. Instead, simply:
Move your file to the static folder, and then change your fetch URL to:
const fileName = 'hello_world.txt'
const filePath = '/' + fileName // or simply '/hello_world.txt'
Then I think your fetch call will correctly load the file.
Reference docs: