79441448

Date: 2025-02-15 11:52:25
Score: 0.5
Natty:
Report link

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:

https://nuxt.com/docs/guide/directory-structure/public

Reasons:
  • Whitelisted phrase (-1): solution is
  • RegEx Blacklisted phrase (2): I'm a beginner
  • Long answer (-0.5):
  • Has code block (-0.5):
  • Low reputation (0.5):
Posted by: A.Mohammed Eshaan