ZX
ZX
Explore posts from servers
Aarktype
Created by ZX on 10/9/2024 in #questions
File type
I noticed you can do types like File, I was wondering if it's possible to do things like validate file size?
41 replies
HHono
Created by ZX on 6/12/2024 in #help
Experimenting with custom NextJS Server
Hey guys, I'm running into an issue where nextjs is not hydrating properly and hono is giving an error: unhandledRejection: Error [ERR_HTTP_HEADERS_SENT]: Cannot set headers after they are sent to the client Here's the code:
import { HttpBindings, getRequestListener } from "@hono/node-server";
import { Hono } from "hono";
import { createServer } from "http";
import { initialize } from "next/dist/server/lib/router-server";

const NODE_ENV = process.env.NODE_ENV! ?? "development";
const NODE_DEBUG = process.env.NODE_DEBUG!;
const PORT = process.env.PORT! ?? "3000";
const HOSTNAME = process.env.HOSTNAME! ?? "localhost";
const EMPTY_BUFFER = Buffer.alloc(0);

const app = new Hono<{ Bindings: HttpBindings }>();
const listener = getRequestListener(app.fetch);

const main = async () => {
const [handle, handleUpgrade] = await initialize({
dev: NODE_ENV !== "production",
port: parseInt(PORT ?? "3000"),
hostname: HOSTNAME,
dir: process.cwd(),
isNodeDebugging: NODE_DEBUG === "true",
customServer: true,
});

app.all("*", (c) => {
if (c.env.incoming.headers.upgrade) {
return handleUpgrade(c.env.incoming, c.env.incoming.socket, EMPTY_BUFFER);
}
return handle(c.env.incoming, c.env.outgoing);
});

createServer(listener).listen(parseInt(PORT), () => {
console.log(`Listening on port ${PORT}`);
});
};

main();
import { HttpBindings, getRequestListener } from "@hono/node-server";
import { Hono } from "hono";
import { createServer } from "http";
import { initialize } from "next/dist/server/lib/router-server";

const NODE_ENV = process.env.NODE_ENV! ?? "development";
const NODE_DEBUG = process.env.NODE_DEBUG!;
const PORT = process.env.PORT! ?? "3000";
const HOSTNAME = process.env.HOSTNAME! ?? "localhost";
const EMPTY_BUFFER = Buffer.alloc(0);

const app = new Hono<{ Bindings: HttpBindings }>();
const listener = getRequestListener(app.fetch);

const main = async () => {
const [handle, handleUpgrade] = await initialize({
dev: NODE_ENV !== "production",
port: parseInt(PORT ?? "3000"),
hostname: HOSTNAME,
dir: process.cwd(),
isNodeDebugging: NODE_DEBUG === "true",
customServer: true,
});

app.all("*", (c) => {
if (c.env.incoming.headers.upgrade) {
return handleUpgrade(c.env.incoming, c.env.incoming.socket, EMPTY_BUFFER);
}
return handle(c.env.incoming, c.env.outgoing);
});

createServer(listener).listen(parseInt(PORT), () => {
console.log(`Listening on port ${PORT}`);
});
};

main();
I'm wondering if anyone with more experience or insight might have an idea with what's going wrong here
2 replies
DTDrizzle Team
Created by ZX on 2/25/2024 in #help
Getting duplicate key value error with many to many relations
let rows = await database
.select()
.from(usersLikeImages)
.where(
and(
eq(usersLikeImages.userId, session.user.id),
eq(usersLikeImages.imageId, imageId),
),
);

if (rows.length > 0) {
await database
.delete(usersLikeImages)
.where(
and(
eq(usersLikeImages.userId, session.user.id),
eq(usersLikeImages.imageId, imageId),
),
);
} else {
await database.insert(usersLikeImages).values({
userId: session.user.id,
imageId,
});
}
let rows = await database
.select()
.from(usersLikeImages)
.where(
and(
eq(usersLikeImages.userId, session.user.id),
eq(usersLikeImages.imageId, imageId),
),
);

if (rows.length > 0) {
await database
.delete(usersLikeImages)
.where(
and(
eq(usersLikeImages.userId, session.user.id),
eq(usersLikeImages.imageId, imageId),
),
);
} else {
await database.insert(usersLikeImages).values({
userId: session.user.id,
imageId,
});
}
export const usersLikeImages = pgTable("users_like_images", {
userId: text("user_id")
.notNull()
.references(() => users.id),
imageId: uuid("image_id")
.notNull()
.references(() => images.id),
});
export const usersLikeImages = pgTable("users_like_images", {
userId: text("user_id")
.notNull()
.references(() => users.id),
imageId: uuid("image_id")
.notNull()
.references(() => images.id),
});
Does anyone know what might be causing this error?
web:dev: ⨯ ../node_modules/postgres/cjs/src/connection.js (790:25) @ postgres
web:dev: ⨯ PostgresError: duplicate key value violates unique constraint "users_like_images_pkey"
web:dev: at Socket.emit (node:events:518:28)
web:dev: ⨯ ../node_modules/postgres/cjs/src/connection.js (790:25) @ postgres
web:dev: ⨯ PostgresError: duplicate key value violates unique constraint "users_like_images_pkey"
web:dev: at Socket.emit (node:events:518:28)
1 replies