πŸ”§ Need Help with Private Networking Between NestJS and Flask on Railway πŸ”§

Hello everyone! I'm currently working on a project that involves two backends hosted on Railway: 1. Main Backend: Built with NestJS, exposed to the public. 2. Secondary Backend: Built with Python Flask, not exposed to the public, intended to communicate with the NestJS backend through private networking. Both backends are part of the same project on Railway, i've configured the Flask backend's URL in the NestJS settings as follows:
http://${{flask.RAILWAY_PRIVATE_DOMAIN}}:${{flask.PORT}}
http://${{flask.RAILWAY_PRIVATE_DOMAIN}}:${{flask.PORT}}
This results in the URL: http://flask.railway.internal:5000 The Flask server is up & running on PORT 5000, deploy logs:
[2024-03-29 11:55:49 +0000] [7] [INFO] Starting gunicorn 20.0.4
[2024-03-29 11:55:49 +0000] [7] [INFO] Listening at: http://0.0.0.0:5000 (7)
[2024-03-29 11:55:49 +0000] [7] [INFO] Using worker: sync
[2024-03-29 11:55:49 +0000] [11] [INFO] Booting worker with pid: 11
[2024-03-29 11:55:49 +0000] [7] [INFO] Starting gunicorn 20.0.4
[2024-03-29 11:55:49 +0000] [7] [INFO] Listening at: http://0.0.0.0:5000 (7)
[2024-03-29 11:55:49 +0000] [7] [INFO] Using worker: sync
[2024-03-29 11:55:49 +0000] [11] [INFO] Booting worker with pid: 11
Issue: When triggering an action that triggers NestJS to communicate with the Flask backend, I encounter an issue where the NestJS fails to connect to the Flask backend. NestJS Deploy Logs:
Error manipulating image: AxiosError: connect ECONNREFUSED fd12:a038:457a::76:c197:****:5000
port: 5000
address: 'fd12:a038:457a::76:c197:****'
Error manipulating image: AxiosError: connect ECONNREFUSED fd12:a038:457a::76:c197:****:5000
port: 5000
address: 'fd12:a038:457a::76:c197:****'
It seems like the IPV6 address from the private network is resolved correctly. Python Flask main.py:
if __name__ == "__main__":
app.run(host="::", debug=True, port=os.getenv("PORT", default=5000))
if __name__ == "__main__":
app.run(host="::", debug=True, port=os.getenv("PORT", default=5000))
NestJS main.ts:
const app = await NestFactory.create<NestFastifyApplication>(
AppModule,
new FastifyAdapter({ logger: true }), // Enable Fastify's logger
);
const configService = app.get(ConfigService<EnvironmentVariables>);
const PORT = configService.get('PORT', { infer: true });

// Listen on all IPv6 addresses
await app.listen(PORT, '::', () => {
app.get(Logger).log(`Listening on IPv6 port ${PORT}`);
});
const app = await NestFactory.create<NestFastifyApplication>(
AppModule,
new FastifyAdapter({ logger: true }), // Enable Fastify's logger
);
const configService = app.get(ConfigService<EnvironmentVariables>);
const PORT = configService.get('PORT', { infer: true });

// Listen on all IPv6 addresses
await app.listen(PORT, '::', () => {
app.get(Logger).log(`Listening on IPv6 port ${PORT}`);
});
Any help would be greatly appreciated! Thank you! πŸ™
Solution:
```` { "$schema": "https://railway.app/railway.schema.json", "build": { "builder": "NIXPACKS"...
Jump to solution
3 Replies
Percy
Percyβ€’8mo ago
Project ID: N/A
user3249123423
user3249123423β€’8mo ago
N/A Fixed it by adding this railway.json gunicorn config
Solution
user3249123423
user3249123423β€’8mo ago
{
"$schema": "https://railway.app/railway.schema.json",
"build": {
"builder": "NIXPACKS"
},
"deploy": {
"startCommand": "gunicorn -b '[::]:'$PORT main:app",

"restartPolicyType": "ON_FAILURE",
"restartPolicyMaxRetries": 10
}
}
{
"$schema": "https://railway.app/railway.schema.json",
"build": {
"builder": "NIXPACKS"
},
"deploy": {
"startCommand": "gunicorn -b '[::]:'$PORT main:app",

"restartPolicyType": "ON_FAILURE",
"restartPolicyMaxRetries": 10
}
}
Want results from more Discord servers?
Add your server