The content of any path that does not contain an Index File (within a deployment) is rendered using our Directory Listing.

Here is an example of how this could look like:

A preview of how the Directory Listing would look in action

As you can see, the directory listing contains three items:

  • first.php and second.php are Lambdas
  • third.png is a Static File

However, no Index File is present. If one would be present, the path of the Directory Listing would render that file instead.

Index Files

Index Files are rendered in place of the path of the directory they are located in.

For example, visiting the path /about will serve the index file located in the about directory if it exists. This is typically /about/index.html.

Files that match all of the following criteria will be identified as an index:

  • The file name is either index or index.<extension> (where <extension> is any file extension of your choice).
  • The file name does not end with a . or contain multiple . in a row.

If multiple files match this pattern, index.html will take precedence followed by shortest to longest file names. That means index.js will take precedence over index.bundle.js.

Types of List Items

There are two types of list items (which matches the Output of a Build):

  • Static Files (indicated with a blank or picture icon)
  • Lambdas (indicated with a λ icon)

Disabling the Directory Listing

In the case that you would like to hide the Directory Listing for a certain path, you have the following two choices:

Include an Index File

As mentioned above, the Directory Listing will only occur if there is no Index File inside the path the client is trying to access.

That means placing a Index File that looks like a "Not Found" error page inside the path will make the visitor think the path does not exist.

Rewrite to a 404 page

The recommended way to hide Directory Listings, however, is to create a new rewrite using the routes property in now.json like this:

"routes": [
    "src": "/example",
    "dest": "/404.html",
    "status": 404

In the example above, the /example route (which is a directory without an Index File, thus would render a Directory Listing) is rewritten to render the /404.html file instead.

Furthermore, we are setting a status code of 404 to accompany the response.