[Bug] Cannot set trustProxy with fastify-cli
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
-
Use config.js: \\javascript module.exports = { trustProxy: true, port: 3300 } \\ then run: \astify start -l warn --config config.js dist/App.js\
-
Use .env file: \TRUST_PROXY=true\ or \TRUST_PROXY=1\
-
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
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 ->
::1or127.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.
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.