Search code examples
next.jsvercel

How to disable directory listing in Next js deployed to Vercel


I have deployed website built in Next.js and apparently when you deploy a next js app you can find the directory of all the static files and resources which i don't feel very good about.

the directory is generated in this way: mydomain.com/_next/static in my case https://www.ovanya.com/_next/static/

this is the directory: enter image description here

the next js docs say:

To prevent showing a Directory Listing page, add an index file, such as index.html, which will then show that file instead when accessing the directory's path.

but i really don't understand what directory should i add the index.html file to? so where should i exatcly put the index.html at?

and another question: is it bad if i leave this just like that? does it have any risks or stuff like that?


Solution

  • 2021 Update

    You can disable directory listing in Project settings -> Advanced (see docs).

    Before 2021

    You need to add index.html to _next and every child directory recursively. You could do it by writing a post-build script that would do it.

    But, there is no benefit doing so. There is no risk of exposing this directory or files inside it.

    _next/static is just compiled client-side public assets.