2 days ago
Server starts successfully (indicated by deploy logs)
I tried to do a bunch of request logging and it not showing incoming requests
Getting the 502 errors on all endpoints
This appears to be a Railway networking issue
My server starts successfully and listens on port 8080 with all routes registered correctly. I have extensive request logging middleware that should capture ANY incoming request, but despite multiple attempts to access the site, zero requests reach my application. Railway's proxy returns 502 errors for all routes. Maybe the load balancer cannot reach my container?
12 Replies
2 days ago
Hey there! We've found the following might help you get unblocked faster:
If you find the answer from one of these, please let us know by solving the thread!
2 days ago
Can you provide the snippet of the public network configuration of your service (could be found in the settings of your service of Railway dashboard)?
Also, do provide the initial lines of how your server file is handling requests
2 days ago
Public Networking
Access your application over HTTP with the following domains
the-forge-production-3b2e.up.railway.app
Port 3
ยท
Metal Edge
Domain
Custom port
Enter the port your app is listening on
Target port
Domain Available!
CancelUpdate
Custom Domain
TCP Proxy
Private Networking
Communicate with this service from within the Railway network.
the-forge.railway.internal
IPv6
Ready to talk privately ยท
You can also simply call methe-forge.
DNS
.railway.internal
initial lines of handling requests
require('dotenv').config();
const express = require('express');
const cors = require('cors');
const { Op } = require('sequelize');
const sequelize = require('./config/database');
const Brick = require('./models/Brick');
const Mile = require('./models/Mile');
const Momentum = require('./models/Momentum');
const Purpose = require('./models/Purpose');
const Todo = require('./models/Todo');
const app = express();
const PORT = process.env.PORT;
// Validate PORT
if (!PORT) {
console.error('โ PORT environment variable is not set');
process.exit(1);
}
console.log("โ
PORT is:", PORT);
// Middleware
app.use(cors({
origin: [
'https://the-forge-app.netlify.app',
'https://the-forge-app.netlify.app/',
'http://localhost:3000',
'http://localhost:3001',
'http://127.0.0.1:3000',
'http://127.0.0.1:3001'
],
credentials: true,
methods: ['GET', 'POST', 'PUT', 'DELETE', 'OPTIONS'],
allowedHeaders: ['Content-Type', 'Authorization']
}));
app.use(express.json());
// Add request logging middleware
app.use((req, res, next) => {
console.log(`๐ฅ ${req.method} ${req.url} - ${new Date().toISOString()}`);
next();
});
2 days ago
Thanks for the info. Just a few more questions:
a. Are you using "custom domain"
b. I was asking for the screenshot of the networking section (attaching one for your reference). Do provide one for your service
By the way, I guess you have missed the app.listen
call. As you may not be providing any PORT variable in the environment for your service, the PORT must be undefined too! So, do these changes overall:
const PORT = process.env.PORT || 5050;
app.listen(PORT, '0.0.0.0', () => { console.log(`
Server listening on port ${PORT}`); });
I am sure that would make your server function properly
Attachments
2 days ago
Incorrect Port Configuration in Railway Dashboard
Go to Railway Dashboard โ your project โ service settings
Under "Custom Port", set
8080
(or whatever your app listens to)Click Update
Example:
Custom port: 8080
AND
Update this:
const PORT = process.env.PORT;
To this:
const PORT = process.env.PORT || 8080;
And in app.listen()
app.listen(PORT, () => { console.log(` Server running on port ${PORT}`); });
2 days ago
Here is the screen shot. I have the app listen at bottom of file
console.log('๐ Starting server initialization...');
try {
sequelize.sync({ force: false })
.then(() => {
console.log('โ
Database synced successfully');
// START SERVER FIRST (immediately after database sync)
const server = app.listen(PORT, () => { // Remove '0.0.0.0' completely
console.log(`๐ฅ Server running on port ${PORT}`);
console.log('โ
Server listening on all available interfaces');
// Railway debugging
console.log('๐ Railway Environment Variables:');
console.log('RAILWAY_ENVIRONMENT:', process.env.RAILWAY_ENVIRONMENT);
console.log('RAILWAY_SERVICE_NAME:', process.env.RAILWAY_SERVICE_NAME);
console.log('RAILWAY_PUBLIC_DOMAIN:', process.env.RAILWAY_PUBLIC_DOMAIN);
console.log('RAILWAY_PRIVATE_DOMAIN:', process.env.RAILWAY_PRIVATE_DOMAIN);
// Network interface debugging
const os = require('os');
const interfaces = os.networkInterfaces();
console.log('๐ Available network interfaces:', Object.keys(interfaces));
// Log all registered routes for debugging
console.log('๐ Registered routes:');
app._router.stack.forEach(function(r){
if (r.route && r.route.path){
console.log(` ${Object.keys(r.route.methods).join(', ').toUpperCase()} ${r.route.path}`);
}
});
});
Attachments
justjaadu
Incorrect Port Configuration in Railway DashboardGo to Railway Dashboard โ your project โ service settingsUnder "Custom Port", set 8080 (or whatever your app listens to)Click Update Example:Custom port: 8080ANDUpdate this:const PORT = process.env.PORT;To this:const PORT = process.env.PORT || 8080;And in app.listen()app.listen(PORT, () => { console.log(` Server running on port ${PORT}`); });
2 days ago
I don't see the custom port in my settings.
kwasifrye
I don't see the custom port in my settings.
2 days ago
custom domain
kwasifrye
Here is the screen shot. I have the app listen at bottom of fileconsole.log('๐ Starting server initialization...'); try { sequelize.sync({ force: false }) .then(() => { console.log('โ Database synced successfully'); // START SERVER FIRST (immediately after database sync) const server = app.listen(PORT, () => { // Remove '0.0.0.0' completely console.log(`๐ฅ Server running on port ${PORT}`); console.log('โ Server listening on all available interfaces'); // Railway debugging console.log('๐ Railway Environment Variables:'); console.log('RAILWAY_ENVIRONMENT:', process.env.RAILWAY_ENVIRONMENT); console.log('RAILWAY_SERVICE_NAME:', process.env.RAILWAY_SERVICE_NAME); console.log('RAILWAY_PUBLIC_DOMAIN:', process.env.RAILWAY_PUBLIC_DOMAIN); console.log('RAILWAY_PRIVATE_DOMAIN:', process.env.RAILWAY_PRIVATE_DOMAIN); // Network interface debugging const os = require('os'); const interfaces = os.networkInterfaces(); console.log('๐ Available network interfaces:', Object.keys(interfaces)); // Log all registered routes for debugging console.log('๐ Registered routes:'); app._router.stack.forEach(function(r){ if (r.route && r.route.path){ console.log(` ${Object.keys(r.route.methods).join(', ').toUpperCase()} ${r.route.path}`); } }); });
2 days ago
As you have designated a PORT number 3 for you. Click on the edit pencil icon that is being shown in the PUBLIC networking section (whose screenshot you provided), and make it somewhat above 5000 (maybe 5050). Then redeploy it, and provide the build logs.
Do you have a base route defined for your server (so that you can see something when the base endpoint is entered)?
clashing
As you have designated a PORT number 3 for you. Click on the edit pencil icon that is being shown in the PUBLIC networking section (whose screenshot you provided), and make it somewhat above 5000 (maybe 5050). Then redeploy it, and provide the build logs. Do you have a base route defined for your server (so that you can see something when the base endpoint is entered)?
2 days ago
Port 3
was something OP set themselves, not something Railway automatically assigned.
brody
Port 3 was something OP set themselves, not something Railway automatically assigned.
2 days ago
Thanks for clarifying that
clashing
As you have designated a PORT number 3 for you. Click on the edit pencil icon that is being shown in the PUBLIC networking section (whose screenshot you provided), and make it somewhat above 5000 (maybe 5050). Then redeploy it, and provide the build logs. Do you have a base route defined for your server (so that you can see something when the base endpoint is entered)?
6 hours ago
DId that helped, kwasifrye?
If yes, then please mark my previous post as the reply