Support Forums

Functions directory is visible over the web

My functions directory is visible over the web when I enter for example https://example.com/functions/hello.js

Is this intended behavior? According to the Netlify docs:

the [functions] directory is not visible over the web unless you place it in your site’s publish directory (not recommended).

However my publish directory is public so functions shouldn’t be visible to users… or am I misunderstanding something?

Screen Shot 2021-06-14 at 8.51.47 PM

Build Settings:
Base directory: Not set
Build command: Not set
Publish directory: public/
Builds: Active

Functions Directory: Not set
(I’m using the default configuration as mentioned in the docs (“If you don’t configure a custom functions directory, Netlify will use netlify/functions as the default and deploy any functions you save there”).

Thank you

Hi @vcamp

How are you deploying your site? Via the Netlify CLI? From GitHub?

Built functions are available at /.netlify/functions/<function-name> (without the .js) so I am thinking there is possibly an error in your directory structure.

Thanks @coelmay. My site is deployed from GitHub.

Calling the function (without the .js) works perfectly:

But I thought this URL was supposed to be hidden (with .js):

These URLS are from this Netlify repo but it illustrates the same issue I’m seeing with my app.

I can’t speak for the Netlify site, but testing on one of my sites I am unable to access a function via /functions/<function-name>.js; can only access via /.netlify/functions/<function-name>

@coelmay Hm that’s interesting. Would you mind screenshotting your directory structure and build settings? Just trying to get some clues here. Thanks.

This is a very basic structure for a static site:

Directory structure (example):

├── functions
│   └── hello.js
├── netlify.toml
└── public
    ├── css
    │   └── styles.css
    ├── img
    │   └── logo.png
    ├── index.html
    └── js
        └── app.js

netlify.toml (example)

  functions = "functions"
  publish = "public"

It works now.

The solution (in this case) was to set Functions > Settings > Functions Directory to functions.

I did it through the Netlify UI but netlify.toml would likely work too.

It’s strange that you have to explicitly set the directory to functions because the Netlify UI clearly states that functions will be used as the default, but that fixed it.

Thanks for your help.

1 Like