2 months ago
I have a simple bun api that runs on PORT 5009 that i have set in variables. I have changes it to other ports. no matter what i get EADDRINUSE
railpack config
{
"$schema": "https://schema.railpack.com",
"steps": {
"build": {
"commands": [
"bun run clean",
"bun prisma generate",
"bun build --compile --outfile=dist/transcriber-api src/index.ts"
],
"outputs": [
"dist/transcriber-api"
]
}
},
"deploy": {
"startCommand": "./dist/transcriber-api"
}
}railway config
{
"$schema": "https://railway.app/railway.schema.json",
"build": {
"builder": "RAILPACK"
},
"deploy": {
"startCommand": "./dist/transcriber-api",
"healthcheckPath": "/healthcheck",
"healthcheckTimeout": 100,
"restartPolicyType": "ON_FAILURE",
"restartPolicyMaxRetries": 10
}
}index file
import { logger } from "@bogeychan/elysia-logger";
import cors from "@elysiajs/cors";
import swagger from "@elysiajs/swagger";
import Elysia from "elysia";
import { helmet } from "elysia-helmet";
import { startJobs } from "./jobs";
import audioRouter from "./routers/audio";
import jobsRouter from "./routers/jobs";
import promptRouter from "./routers/prompt";
import { logger as appLogger } from "./utils/logger";
const baseRouter = new Elysia()
.use(
swagger({
path: process.env.NODE_ENV === "production" ? undefined : "/swagger",
documentation: {
info: {
title: "TRANSCRIBER API",
version: "1.0.0",
},
},
exclude:
process.env.NODE_ENV === "production"
? ["/swagger"]
: ["/sso/callback"],
}),
)
.use(
cors({
origin: true,
}),
)
.use(logger())
.use(helmet({}))
.get("/healthcheck", () => ({ status: "ok" }), { tags: ["Healthcheck"] })
.use(promptRouter)
.use(audioRouter)
.use(jobsRouter)
.onError(({ code, error, set }) => {
appLogger.error(
error,
`Error in base router --- ${set.status} --- ${code}`,
);
});
baseRouter.listen({ port: Bun.env.PORT, hostname: "0.0.0.0" }, () =>
appLogger.info(
`Base router is running at http://localhost:${baseRouter.server?.port}`,
),
);
startJobs();
export default baseRouter;
6 Replies
2 months 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 months ago
In pretty much every case I've seen this error occur, it's been from users who started their app on the same port more than once. Are you sure you're not listening on the same port anywhere else? Also, check whether you see the Base router is running at ... log-line anywhere in your app before the error message
2 months ago
My api has only one start point. I am compiling my application into binary and running it. I am not sure why it is being run multiple times
2 months ago
I am not sure why it is being run multiple times
Does that mean you confirmed that it is running multiple times? Just want to make sure we're on the same page here
2 months ago
I see two possible places this could be happening in your index.ts:
You have
baseRouter.listen(...)at the end of your file.You also have
export default baseRouter;. Many modern frameworks like Elysia automatically start the server on their own when you export the instance.
Can you try this? Remove the entire baseRouter.listen(...) block from your index.ts file and deploy again. Just keep the export default baseRouter;. The framework should handle the server start for you.
Let me know if that works
2 months ago
That worked. but wierd
I think this happens only when compiled. because i have other application that i run as docker images. It does not happen when you run locally using
bun run --watch src/index.tsThanks
Status changed to Solved brody • 3 months ago