How to setup N8N_ADDITIONAL_NON_UI_ROUTES?

Describe the problem/error/question

Hey guys, I deployed n8n within portainer, I need to do some verification with a static file must be placed at the root of the n8n instance.

I tried to set N8N_ADDITIONAL_NON_UI_ROUTES to xxxx_verify.txt and xxxx_verify.txt:xxxx_verify as the environment on portainer, and mounted the txt file to /usr/local/lib/node_modules/n8n/dist/, but still got 404 error on https://test.test.com/xxxx_verify.txt.

What is the error message (if any)?

Cannot GET /xxxx_verify.txt

Please share your workflow

  1. touch verification file and write content to it.
  2. mount host path to container
  3. add environment to the container
  4. visit url

Share the output returned by the last node

Information on your n8n setup

  • n8n version: docker latest
  • Database (default: SQLite): postgresql
  • n8n EXECUTIONS_PROCESS setting (default: own, main): own
  • Running n8n via (Docker, npm, n8n cloud, desktop app): docker on portainer
  • Operating system: centos

Are you able to use something like an nginx reverse proxy? You can route to any URL/file that way. We have one client on n8n.domain.net and all reports are hosted at n8n.domain.net/reports. We just routed /reports to a directory on the host via nginx config.

Where did you find the N8N_ADDITIONAL_NON_UI_ROUTES env var? I have not seen it before and its not in the documentation.
*I was in fact able to find it via github, where it was added in 2022 and doesn’t seem to referenced anywhere else. I do believe it works sort of how you think, where it prevents certain routes to not proc the UI.

But:

  1. I (think) it seems to only be valid for routes, not files.
  2. I (think) this is potentially used only internally, as some env vars are not adjustable.

I would advise trying to use some kind of reverse proxy webserver like nginx to force sub routes.

Hi. I figured this out, by mapping a edited source file, because the env vars didn’t work as expected, I think maybe the env vars not parsed properly.

Since there’re no documentations, I just hardcoded the routes, adding the env vars there, and it’s working.

Maybe it’s time for updating the documentation.

Thank you anyway.

Like I said, that is an undocumented feature and I am unsure if its intended to be used how you tried to use it.

Could you provide your setup for when others try use this to provide more context in how you solved? As there is no other details online about it I was able to easily find.

Of course.

First, set the following env vars:

  • N8N_EDITOR_BASE_URL
  • WEBHOOK_URL
    to be the desired subdomain name, eg. n8n.abc.com

Next, map a locally modified server.js to the container path: /usr/local/lib/node_modules/n8n/dist/server.js

And here’s the modified server.js, only line #311 is added, no more other changes, you can use docker cp to copy the original file out, then modify it:

303             const nonUIRoutes = [
304                 'favicon.ico',
305                 'assets',
306                 'static',
307                 'types',
308                 'healthz',
309                 'metrics',
310                 'e2e',
311                 'put_your_file_name_here.txt',
312                 this.restEndpoint,
313                 this.endpointPresetCredentials,
314                 (0, public_api_1.isApiEnabled)() ? '' : publicApiEndpoint,
315                 ...this.globalConfig.endpoints.additionalNonUIRoutes.split(':'),
316             ].filter((u) => !!u);
317             const nonUIRoutesRegex = new RegExp(`^/(${nonUIRoutes.join('|')})/?.*$`);

Hope it’ll be helpful.

1 Like

If you are running n8n in production, I’d recommend using a reverse proxy (if you aren’t using one already), and then routing the urls in the reverse-proxy to another static file server.
The additional routes option is neither well documented, nor commonly used, and might disappear in a future version of n8n.
Routing these on a reverse proxy would be a much safer option in the long term.

1 Like

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.