fastify-cli icon indicating copy to clipboard operation
fastify-cli copied to clipboard

[Bug] Cannot set trustProxy with fastify-cli

Open shanliuling opened this issue 8 months ago • 2 comments

Prerequisites

  • [X] I have written a descriptive issue title
  • [X] I have searched existing issues to ensure the bug has not already been reported

Fastify version

4.12.0

Node.js version

18.12.1

Operating system

macOS

Description

I cannot set trustProxy to true when starting my fastify server with fastify-cli.

Steps to Reproduce

  1. Use config.js: \\javascript module.exports = { trustProxy: true, port: 3300 } \\ then run: \ astify start -l warn --config config.js dist/App.js\

  2. Use .env file: \TRUST_PROXY=true\ or \TRUST_PROXY=1\

  3. Pass env variable: \TRUST_PROXY=true fastify start -l warn dist/App.js\

None of them are setting trustProxy to true. The only way it works is by creating the server manually with trustProxy: true in code.

Expected Behavior

I expected at least one of them to work, the env file or config.js

shanliuling avatar Mar 21 '26 17:03 shanliuling

Hi! the correct flag and env var names are:

CLI flag

npm start -- --trust-proxy-enabled

Env var (note the FASTIFY_ prefix)

FASTIFY_TRUST_PROXY_ENABLED=true npm start

To verify it works add this route for test:

  fastify.get('/trust-proxy', async function (request, reply) {
    return {
      ip: request.ip
    };
  });

Then run for example:

curl -H "X-Forwarded-For: 1.2.3.4" http://localhost:3000/trust-proxy
  • Without flag -> ::1 or 127.0.0.1 (trustProxy off)
  • With flag -> 1.2.3.4 (trustProxy on)

The TRUST_PROXY env var doesn't work because the CLI expects the FASTIFY_ prefix.

Tony133 avatar May 28 '26 07:05 Tony133

This issue has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.

github-actions[bot] avatar Oct 01 '26 03:10 github-actions[bot]