2 years ago
Using Bun and Hono to run a server, don't quite know where this error is coming from.
42 Replies
2 years ago
please include more information, where are you seeing this error? what have you tried to do to fix this? etc etc
seeing this error after deploy is finished; prisma generates it's client and hono starts up the server. it crashes right after. i really don't know where this is coming from otherwise i would try to provide more information
import { Hono } from "hono";
import type { User } from "@prisma/client";
type Variables = {
stytchId: string,
user: User
}
const app = new Hono<{ Variables: Variables }>();
import * as api from "./api";
import { DB, ERRGEN, STYTCH } from "./constants";
app.get("/", (c) => c.text("Hello from Spaceman Gaming!"));
// All user paths check the JWT to fetch the user
// They set the user as a variable on the request, so it can be processed by the called method
app.use("/user/*", async (c, next) => {
try {
const jwt = c.req.header("x-lots-auth");
if (!jwt) {
throw ERRGEN(401, "JWT not found!")
}
const decoded = await STYTCH.sessions.authenticateJwtLocal({ session_jwt: jwt })
c.set("stytchId", decoded.user_id);
await next();
} catch (e: any) {
if (!e.code) { e.code = 500; }
console.log(`ERROR: ${e.code} ${e.message}`)
return c.json({ success: false, error: e.message }, e.code);
}
});
app.use("/user/me/*", async (c, next) => {
try {
const user = await DB.user.findUnique({ where: { stytchId: c.get("stytchId") } });
if (!user) {
throw ERRGEN(400, "User not found!")
}
c.set('user', user);
await next();
} catch (e: any) {
if (!e.code) { e.code = 500; }
console.log(`ERROR: ${e.code} ${e.message}`)
return c.json({ success: false, error: e.message }, e.code);
}
})
// TODO: This currently returns the full user object; we want to return some subset of this information probably?
// Or attach more info to this through other database models (such as wallets)
app.get("/user/me", async (c) => {
return await api.getUser(c);
})
app.post("/user/register", async (c) => {
return await api.registerUser(c);
})
console.log(`Hono running on port ${process.env.PORT || 3000}`);
export default {
port: process.env.PORT || 3000,
fetch: app.fetch
};^index.ts file
2 years ago
have you simply tried googling that error? as it's not an error that would strictly be related to the platform
yup tried googling it, but didn't return anything helpful. also the code runs the server locally
2 years ago
what version of bun do you use locally?
2 years ago
what version of bun is railway using?
i didn't specify a version for bun in config, is there an easy way to find out what version it's using?

2 years ago
print the version in code
2 years ago
before the error happens
i can try downgrade local version and see what happens but don't think that one minor version change would've caused this
2 years ago
I don't think so either
2 years ago
can you send that error as a message, I'm on mobile and I can't copy the form title apparently
2 years ago
do you have a .env file in your repo?
2 years ago
what do you run to start your app locally?
2 years ago
what version of node do you have installed locally?
2 years ago
well can't hurt to run node 18 and bun 1.1.8 locally and see what happens
trying to figure out how to downgrade bun, but node downgrade and it still works
2 years ago
nvm makes that quite easy
2 years ago
have you tried writing a simple Dockerfile for Railway to use?
2 years ago
I unfortunately don't have a bun dockerfile on hand, but there would be many great examples online, once you see one you will know how to use or modify them to your needs
right, i'm just trying to figure out the motivation on the bun dockerfile :- i'm not doing anything special with bun, the env error seems to be (i could be totally wrong) from a conflict with how railway is injecting env and how bun is expecting it; unsure what part of dockerfile to modify to change that conflict
2 years ago
Railway doesn't do anything special they are just environment variables, I think this is something nixpacks is doing wrong and a Dockerfile would answer that question
just to close this out, couldnt' figure it out with bun so just reverted to hosting with traditional node
2 years ago
did you get to try a dockerfile?
2 years ago
marking that as solved since another use had the same issue and a Dockerfile solved it for them.





