bun + turborepo monorepo application failing to respond
heybereket
PROOP

2 years 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

120 Replies

heybereket
PROOP

2 years ago

aac0388c-812d-41d2-abad-f664d8a4fc9f


brody
EMPLOYEE

2 years ago

make sure you are listening on the $PORT environment variable


heybereket
PROOP

2 years ago

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}`);
  });

heybereket
PROOP

2 years ago

1254618360361124000


heybereket
PROOP

2 years ago

seem to be getting this now, weird


brody
EMPLOYEE

2 years ago

there is no HOST variable, just use 0.0.0.0


heybereket
PROOP

2 years ago

I have it set to (where these are under the env cost)


heybereket
PROOP

2 years ago

HOST: z.string().default("0.0.0.0"),
API_URL: z.string().default("http://localhost:8080"),

heybereket
PROOP

2 years ago

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}`);
  });

brody
EMPLOYEE

2 years ago

what is PORT set to in zod ?


heybereket
PROOP

2 years ago

PORT: z.number().default(8080),
HOST: z.string().default("0.0.0.0"),

brody
EMPLOYEE

2 years 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


heybereket
PROOP

2 years ago

will try rn


heybereket
PROOP

2 years ago

but i doubt thats the issue since it should be defined


brody
EMPLOYEE

2 years ago

is it? do you have a PORT service variable?


brody
EMPLOYEE

2 years ago

you'd still want to be listening on the PORT environment variable in code though


heybereket
PROOP

2 years ago

1254621745521102800


heybereket
PROOP

2 years ago

running into this issue now


heybereket
PROOP

2 years ago

when i try to deploy those new changes (but anything really)


heybereket
PROOP

2 years ago

1254621885161934800


heybereket
PROOP

2 years ago

keeps retrying


brody
EMPLOYEE

2 years ago

would you happen to have a custom start command set now?


heybereket
PROOP

2 years ago

1254621967462568000


heybereket
PROOP

2 years ago

1254621983140876300


heybereket
PROOP

2 years ago

the structure of my codebase is:

apps
-> api
package.json

brody
EMPLOYEE

2 years 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


heybereket
PROOP

2 years ago

oh will turn that on


heybereket
PROOP

2 years ago

nope i dont


heybereket
PROOP

2 years ago

misread my bad


heybereket
PROOP

2 years ago

1254622160140501000


brody
EMPLOYEE

2 years ago

hmmm well those logs are not helpful, bun never prints anything helpful it seems


brody
EMPLOYEE

2 years ago

I assume you can still run the same pair of build and start commands locally without issues?


heybereket
PROOP

2 years ago

yeah


heybereket
PROOP

2 years ago

it all works locally


heybereket
PROOP

2 years ago

same start & build commands


brody
EMPLOYEE

2 years ago

even if you deleted the project and did another clone?


heybereket
PROOP

2 years ago

on railway or git


brody
EMPLOYEE

2 years ago

on git, delete the project locally and clone it again


brody
EMPLOYEE

2 years 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


heybereket
PROOP

2 years ago

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"
  }
}

heybereket
PROOP

2 years ago

i use bun@1.0.21


brody
EMPLOYEE

2 years ago

what version does railway use?


heybereket
PROOP

2 years ago

where can i check that?


brody
EMPLOYEE

2 years ago

temporarily change the start command to a command that prints the version of bun


heybereket
PROOP

2 years ago

alright


heybereket
PROOP

2 years ago

1254624040493256700


heybereket
PROOP

2 years ago

ok


heybereket
PROOP

2 years ago

1254626867206689000


heybereket
PROOP

2 years ago

used the railway cli


heybereket
PROOP

2 years ago

thank god i got a bit more context


brody
EMPLOYEE

2 years ago

are you on the v2 runtime?


heybereket
PROOP

2 years ago

yeah


brody
EMPLOYEE

2 years ago

also, I the API app not with bun?


heybereket
PROOP

2 years ago

wdym


brody
EMPLOYEE

2 years ago

node dist/index.js


heybereket
PROOP

2 years ago

1254627588866048000


heybereket
PROOP

2 years ago

got it up to this point now


heybereket
PROOP

2 years ago

still getting

Application failed to respond


heybereket
PROOP

2 years ago

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"
  },

brody
EMPLOYEE

2 years ago

we are back to this, please make these changes


heybereket
PROOP

2 years ago

oh shoot


heybereket
PROOP

2 years ago

forgot to change that back


heybereket
PROOP

2 years ago

what's the port railway uses by default?


heybereket
PROOP

2 years ago

just curious


brody
EMPLOYEE

2 years ago

it's random, that's why your app needs to listen on the PORT environment variable


brody
EMPLOYEE

2 years ago

please make this change


heybereket
PROOP

2 years ago

doing that rn


heybereket
PROOP

2 years ago

alright


heybereket
PROOP

2 years ago

just tried with:


heybereket
PROOP

2 years ago

  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}`);
    }
  );

heybereket
PROOP

2 years ago

seems to keep using 8080 thought, so PORT must not be defined by railway


heybereket
PROOP

2 years ago

1254629877358002200


heybereket
PROOP

2 years ago

wtf


heybereket
PROOP

2 years ago

am i doing something wrong


heybereket
PROOP

2 years ago

ok so


heybereket
PROOP

2 years ago

apparently it works if i just manually add PORT to my env variables


heybereket
PROOP

2 years ago

lmfao


heybereket
PROOP

2 years ago

thank you


brody
EMPLOYEE

2 years ago

while that will work, and it's by far the simpler way this is not the recorded way


heybereket
PROOP

2 years ago

okay


heybereket
PROOP

2 years ago

so after a bit of debugging


heybereket
PROOP

2 years ago

it seems like dotenv just doesnt want to parse the env variable on railway


heybereket
PROOP

2 years ago

it works locally though, which is weird


brody
EMPLOYEE

2 years ago

dotenv parses .env files


heybereket
PROOP

2 years ago

yeah


brody
EMPLOYEE

2 years ago

railway does not create .env files


brody
EMPLOYEE

2 years ago

they inject the variables directly into the environment


heybereket
PROOP

2 years ago

wdym


heybereket
PROOP

2 years ago

how would process.env not work?


heybereket
PROOP

2 years ago

i understand this


heybereket
PROOP

2 years ago

but not this


brody
EMPLOYEE

2 years ago

I don't know how I could clarify further


heybereket
PROOP

2 years ago

well maybe i can explain what i mean


heybereket
PROOP

2 years ago

i have variables that i set on railway, like below:

1254647356222079200


heybereket
PROOP

2 years ago

and im accessing them through process.env


heybereket
PROOP

2 years ago

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


brody
EMPLOYEE

2 years ago

your code is doing something to unset them


heybereket
PROOP

2 years ago

oh actually


heybereket
PROOP

2 years ago

i think the issue is that the env variables are located in the root directory


heybereket
PROOP

2 years ago

and not in apps/api


brody
EMPLOYEE

2 years ago

the environment variables are injected into the containers environment, they aren't scoped to any specific directory


brody
EMPLOYEE

2 years ago

in a production environment like railway you don't even need to call dotenv


heybereket
PROOP

2 years ago

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);

heybereket
PROOP

2 years ago

1254651664061829000


heybereket
PROOP

2 years ago

I have it set in Railway


heybereket
PROOP

2 years ago

and in my src/index.ts, all I do is


heybereket
PROOP

2 years ago

console.log(env.DATABASE_URL)


heybereket
PROOP

2 years ago

and for some reason it doesn't return the value that I put in railway


heybereket
PROOP

2 years ago

and instead that fallback of default db url goes here


brody
EMPLOYEE

2 years ago

can zod even parse process.env


heybereket
PROOP

2 years ago

yes


brody
EMPLOYEE

2 years ago

haha don't say yes, if it could, it would work


heybereket
PROOP

2 years ago

have done it before + works locally


brody
EMPLOYEE

2 years ago

so you have something missconfigured


heybereket
PROOP

2 years ago

will try without using zod for it


heybereket
PROOP

2 years ago

import "dotenv/config";

export const env = {
  DATABASE_URL: process.env.DATABASE_URL || "postgres://butler:butler@127.0.0.1:5432/postgres",
  // ... other variables
};

heybereket
PROOP

2 years ago

doesn't seem to work with this either


heybereket
PROOP

2 years ago

the thing is it works fine locally so i can't repro it


brody
EMPLOYEE

2 years ago

something you are doing is un-setting them


brody
EMPLOYEE

2 years ago

try removing dotenv because as mentioned, you don't need to call it


Loading...