a year ago
In RedwoodJs project. Can't seem to get past healthcheck. added railway.toml with this:
[build]
builder = "nixpacks"
buildCommand = "yarn rw build"
[deploy]
startCommand = "yarn rw serve"
healthcheckPath = "/health"
healthcheckTimeout = 180
restartPolicyType = "on_failure"
[phases.setup]
cmds = ["yarn install"]
[phases.build]
cmds = [
# Build commands only
]
health check endpoint does this:
import { db } from 'src/lib/db'
export const handler = async () => {
try {
// Perform a simple database query to ensure connectivity
const userCount = await db.user.count()
return {
statusCode: 200,
headers: {
'Content-Type': 'application/json',
},
body: JSON.stringify({
status: 'ok',
timestamp: new Date().toISOString(),
dbConnected: true,
userCount,
environment: process.env.NODE_ENV || 'unknown',
database: process.env.DATABASE_URL ? 'configured' : 'missing',
}),
}} catch (error) {
console.error('Health check failed:', error)
return {
statusCode: 500,
headers: {
'Content-Type': 'application/json',
},
body: JSON.stringify({
status: 'error',
timestamp: new Date().toISOString(),
error: error.message,
stack: process.env.NODE_ENV === 'development' ? error.stack : undefined,
}),
}}
}
Looks like this might be a common issue? What am I missing?
ⓘ Deployment information is only viewable by project members and Railway employees.
1 Replies
a year ago
Hello,
The PORT variable is used to know what port to use internally for the health check, but it looks like you have set it to the port for MongoDB.
You should have the PORT variable set to the port your application listens on and use a different port for MongoDB.
Best,
Brody