a year ago
For some reason my application is saying it's failing to respond, however it successfully deploys (or at least it says so…)
I have PORT
configured for Railway's default to be injected, so that isn't the issue. I also setup both my start & build scripts, which are:
Start: bun start --filter=api
Build: bun run build --filter=api
0 Replies
a year ago
make sure you are listening on the $PORT environment variable
server.listen({ host: process.env.HOST, port: process.env.PORT }, (err, address) => {
if (err) {
Logger.error("SERVER", err.message);
process.exit(1);
}
Logger.info("SERVER", `Listening at ${address}`);
});
a year ago
there is no HOST variable, just use 0.0.0.0
HOST: z.string().default("0.0.0.0"),
API_URL: z.string().default("http://localhost:8080"),
Sorry, it shouldn't been:
server.listen({ host: env.HOST, port: env.PORT }, (err, address) => {
if (err) {
Logger.error("SERVER", err.message);
process.exit(1);
}
Logger.info("SERVER", `Listening at ${address}`);
});
a year ago
what is PORT set to in zod ?
a year ago
you should use process.env.PORT instead, and if that isn't available then you can default to 8080, not sure what that looks like in zod though
a year ago
is it? do you have a PORT service variable?
a year ago
you'd still want to be listening on the PORT environment variable in code though
a year ago
would you happen to have a custom start command set now?
a year ago
do you have the new builder also enabled? the new builder has a bug where it doesn't pass in the start command correctly
a year ago
hmmm well those logs are not helpful, bun never prints anything helpful it seems
a year ago
I assume you can still run the same pair of build and start commands locally without issues?
a year ago
even if you deleted the project and did another clone?
a year ago
on git, delete the project locally and clone it again
a year ago
what version of bun do you use locally, and what version of bun is railway using for your project? it's always best to have the cloud platform running the same versions of stuff as you run locally
this is what my package.json looks like:
{
"name": "test",
"private": true,
"scripts": {
"build": "turbo build",
"dev": "turbo dev",
"start": "turbo start",
"lint": "turbo lint",
"format": "prettier --write \"**/*.{ts,tsx,md}\""
},
"devDependencies": {
"prettier": "^3.3.0",
"turbo": "latest"
},
"engines": {
"node": ">=18"
},
"packageManager": "bun@1.0.21",
"workspaces": [
"apps/*"
],
"dependencies": {
"tsc-alias": "^1.8.10"
}
}
a year ago
what version does railway use?
a year ago
temporarily change the start command to a command that prints the version of bun
a year ago
are you on the v2 runtime?
a year ago
also, I the API app not with bun?
a year ago
node dist/index.js
in the api package, my scripts are:
"scripts": {
"dev": "tsx watch --clear-screen=false src/index.ts",
"migrate": "drizzle-kit generate",
"build": "tsc -p tsconfig.json && tsc-alias -p tsconfig.json",
"start": "node dist/index.js"
},
a year ago
we are back to this, please make these changes
a year ago
it's random, that's why your app needs to listen on the PORT environment variable
a year ago
please make this change
server.listen(
{
host: process.env.HOST ?? "0.0.0.0",
port: process.env.PORT ? Number(process.env.PORT) : 8080,
},
(err, address) => {
if (err) {
Logger.error("SERVER", err.message);
process.exit(1);
}
Logger.info("SERVER", `Listening at ${address}`);
}
);
a year ago
while that will work, and it's by far the simpler way this is not the recorded way
a year ago
dotenv parses .env files
a year ago
railway does not create .env files
a year ago
they inject the variables directly into the environment
a year ago
I don't know how I could clarify further
but when i test it by console logging, like console.log([process.env.GOOGLE](process.env.GOOGLE)_CLIENT_ID ?? "some google client id")
, it doesn't work, and goes to the fallback of some google client id
a year ago
your code is doing something to unset them
i think the issue is that the env variables are located in the root directory
a year ago
the environment variables are injected into the containers environment, they aren't scoped to any specific directory
a year ago
in a production environment like railway you don't even need to call dotenv
this is my src/utils/env.ts
:
import "dotenv/config";
import { z } from "zod";
export const env = z
.object({
DATABASE_URL: z
.string()
.default("default db url goes here"),
// ... other variables
})
.parse(process.env);
a year ago
can zod even parse process.env
a year ago
haha don't say yes, if it could, it would work
a year ago
so you have something missconfigured
import "dotenv/config";
export const env = {
DATABASE_URL: process.env.DATABASE_URL || "postgres://butler:butler@127.0.0.1:5432/postgres",
// ... other variables
};
a year ago
something you are doing is un-setting them
a year ago
try removing dotenv because as mentioned, you don't need to call it