playsonmac
playsonmac
Explore posts from servers
HHono
Created by playsonmac on 2/2/2025 in #help
Websocket subprotocol results in Error: The script will never generate a response
Woah, thanks! I'll look into it!
23 replies
HHono
Created by playsonmac on 2/2/2025 in #help
Websocket subprotocol results in Error: The script will never generate a response
I might fall back to just sending the token as a query param
23 replies
HHono
Created by playsonmac on 2/2/2025 in #help
Websocket subprotocol results in Error: The script will never generate a response
I appreciate your help 🙌
The issue is I'm only using workers through hono and I don't really know how to surface any of the interals. I'm literally using the hono upgradeWebSocket hanlder on one of the routes of the hono app.
23 replies
HHono
Created by playsonmac on 2/2/2025 in #help
Websocket subprotocol results in Error: The script will never generate a response
Oh, do you mean on the frontend? Here's my frontend implementation:
const handleWS = async () => {
const wsUrl = `${process.env.NEXT_PUBLIC_API_URL}/ws`;

const ws = new WebSocket(wsUrl, ["Authorization", "sometoken"]);

// Just added this but doesn't really help..
ws.addEventListener("close", () => {
ws.close();
});

ws.onopen = () => {
setWsStatus("Open");
const initMessage = JSON.stringify({
type: "init",
payload: { userId: "user-123", message: "Test message from client" },
});
ws.send(initMessage);
};

ws.onmessage = (event) => {
try {
const data = JSON.parse(event.data);
switch (data.type) {
case "ack":
console.log("Ack received:", data.payload.responseId);
break;
case "data":
setStreamData((prev) => prev + data.payload.chunk);
break;
case "complete":
setWsStatus("Completed");
break;
case "error":
console.error("Error from server:", data.payload.message);
setWsStatus(`Error: ${data.payload.message}`);
break;
default:
console.warn("Unknown message type:", data.type);
}
} catch (err) {
console.error("Failed to parse message:", err);
}
};

ws.onclose = (event) => {
console.log(`WebSocket closed: ${event.code} - ${event.reason}`);
setWsStatus(`Closed: ${event.code} - ${event.reason}`);
};

ws.onerror = (event) => {
console.log("WebSocket encountered error:", JSON.stringify(event));
setWsStatus("Error encountered");
};
};
const handleWS = async () => {
const wsUrl = `${process.env.NEXT_PUBLIC_API_URL}/ws`;

const ws = new WebSocket(wsUrl, ["Authorization", "sometoken"]);

// Just added this but doesn't really help..
ws.addEventListener("close", () => {
ws.close();
});

ws.onopen = () => {
setWsStatus("Open");
const initMessage = JSON.stringify({
type: "init",
payload: { userId: "user-123", message: "Test message from client" },
});
ws.send(initMessage);
};

ws.onmessage = (event) => {
try {
const data = JSON.parse(event.data);
switch (data.type) {
case "ack":
console.log("Ack received:", data.payload.responseId);
break;
case "data":
setStreamData((prev) => prev + data.payload.chunk);
break;
case "complete":
setWsStatus("Completed");
break;
case "error":
console.error("Error from server:", data.payload.message);
setWsStatus(`Error: ${data.payload.message}`);
break;
default:
console.warn("Unknown message type:", data.type);
}
} catch (err) {
console.error("Failed to parse message:", err);
}
};

ws.onclose = (event) => {
console.log(`WebSocket closed: ${event.code} - ${event.reason}`);
setWsStatus(`Closed: ${event.code} - ${event.reason}`);
};

ws.onerror = (event) => {
console.log("WebSocket encountered error:", JSON.stringify(event));
setWsStatus("Error encountered");
};
};
23 replies
HHono
Created by playsonmac on 2/2/2025 in #help
Websocket subprotocol results in Error: The script will never generate a response
I've highlighted it above. It's the onClose from the docs - https://hono.dev/docs/helpers/websocket
23 replies
HHono
Created by playsonmac on 2/2/2025 in #help
Websocket subprotocol results in Error: The script will never generate a response
Yep, I have it. Everything works until I send a protocol (which I'm trying to use to authenticate the user since websockets don't support typical headers)
app.get(
"/ws",
upgradeWebSocket((c) => {
// console.log("c.req", c.req);
const rawProtocols = c.req.header("sec-websocket-protocol");
console.log(rawProtocols);

return {
onMessage: (evt, ws) => {
console.log("evt in onMessage", evt);
console.log("ws in onMessage", ws);
},

onError(evt, ws) { // < ----------------------- here it is

console.log("evt in onError", evt);
console.log("ws in onError", ws);
},
onClose(evt, ws) {
console.log("evt in onClose", evt);
console.log("ws in onClose", ws);
},
};
})
);
app.get(
"/ws",
upgradeWebSocket((c) => {
// console.log("c.req", c.req);
const rawProtocols = c.req.header("sec-websocket-protocol");
console.log(rawProtocols);

return {
onMessage: (evt, ws) => {
console.log("evt in onMessage", evt);
console.log("ws in onMessage", ws);
},

onError(evt, ws) { // < ----------------------- here it is

console.log("evt in onError", evt);
console.log("ws in onError", ws);
},
onClose(evt, ws) {
console.log("evt in onClose", evt);
console.log("ws in onClose", ws);
},
};
})
);
23 replies
HHono
Created by playsonmac on 2/2/2025 in #help
Websocket subprotocol results in Error: The script will never generate a response
Thanks! Do you mean adding a onClose method tot he return of the upgradeWebSocket handler? I have it (I just trimmed down the minimal example so it doesn't take up space) and I still have the issue. Or do you mean something else?
23 replies
DTDrizzle Team
Created by playsonmac on 1/13/2025 in #help
[Solved] How to see a supabase with references to authUsers.id?
You need to inlcude authUsers import { authUsers } from "drizzle-orm/supabase" in the seed schema which allows you to seed users as well
2 replies
DTDrizzle Team
Created by playsonmac on 1/12/2025 in #help
[Solved] drizzle-seed autocomplete not working if there are enums or zod objects
Turns out anything that is not PgTable (in my case) breaks the autocomplete inside the seed function. When I extracted the tables to a new dbSchema object and pass it to the seed function, the autocomplete works.
5 replies
DTDrizzle Team
Created by playsonmac on 1/12/2025 in #help
[Solved] drizzle-seed autocomplete not working if there are enums or zod objects
It's the enums that are breaking it
5 replies
DTDrizzle Team
Created by playsonmac on 1/12/2025 in #help
[Solved] drizzle-seed autocomplete not working if there are enums or zod objects
Initially I thought its because I had drizzle-zod schemas defined within the same files where the table definitions are but it still doesn't work after I've removed them
5 replies
DTDrizzle Team
Created by playsonmac on 1/12/2025 in #help
[Solved] drizzle-seed autocomplete not working if there are enums or zod objects
Here's the tsconfig:
{
"$schema": "https://json.schemastore.org/tsconfig",
"compilerOptions": {
"composite": false,
"declaration": true,
"declarationMap": true,
"esModuleInterop": true,
"forceConsistentCasingInFileNames": true,
"inlineSources": false,
"isolatedModules": true,
"module": "ESNext",
"moduleResolution": "Bundler",
"moduleDetection": "force",
"useDefineForClassFields": true,
"noFallthroughCasesInSwitch": true,
"skipLibCheck": true,
"strict": true
},
"include": ["**/*.ts", "**/*.js"],
"exclude": ["node_modules"]
}
{
"$schema": "https://json.schemastore.org/tsconfig",
"compilerOptions": {
"composite": false,
"declaration": true,
"declarationMap": true,
"esModuleInterop": true,
"forceConsistentCasingInFileNames": true,
"inlineSources": false,
"isolatedModules": true,
"module": "ESNext",
"moduleResolution": "Bundler",
"moduleDetection": "force",
"useDefineForClassFields": true,
"noFallthroughCasesInSwitch": true,
"skipLibCheck": true,
"strict": true
},
"include": ["**/*.ts", "**/*.js"],
"exclude": ["node_modules"]
}
5 replies
DTDrizzle Team
Created by playsonmac on 1/10/2025 in #help
drizzle-zod 0.6.1 has errors on each createXyzSchema
Thanks!
3 replies
DTDrizzle Team
Created by Filip on 8/10/2024 in #help
Error: self-signed certificate in certificate chain
I couldn't get it to work locally, but it turns out that it actually works in the github action so that's good
10 replies
DTDrizzle Team
Created by Filip on 8/10/2024 in #help
Error: self-signed certificate in certificate chain
I have the same issue with Supabase. There was a post saying that this works:
const caString = fs.readFileSync("xxx.crt").toString();
// URL encode the certificate
const caStringEncoded = encodeURIComponent(caString);

// Construct the database URL with SSL parameters
const dbUrl = new URL(env.DB_URL!);
dbUrl.searchParams.append("sslmode", "require");
dbUrl.searchParams.append("sslrootcert", caStringEncoded);

export default defineConfig({
dialect: "postgresql",
out: "./drizzle",
schema: "./db/schema/*",
dbCredentials: {
url: dbUrl.toString(),
},
schemaFilter: ["public"],
});
const caString = fs.readFileSync("xxx.crt").toString();
// URL encode the certificate
const caStringEncoded = encodeURIComponent(caString);

// Construct the database URL with SSL parameters
const dbUrl = new URL(env.DB_URL!);
dbUrl.searchParams.append("sslmode", "require");
dbUrl.searchParams.append("sslrootcert", caStringEncoded);

export default defineConfig({
dialect: "postgresql",
out: "./drizzle",
schema: "./db/schema/*",
dbCredentials: {
url: dbUrl.toString(),
},
schemaFilter: ["public"],
});
Unfortunately, I get ENAMETOOLONG when I encode the supabase certificate into the dbUrl :/
10 replies