Ahmed Eid
Ahmed Eid
Explore posts from servers
CDCloudflare Developers
Created by Ahmed Eid on 11/6/2024 in #workers-help
Error: [unenv] fs.readFile is not implemented yet when getting presigned url with s3 packages.
I am trying to get a presigned put url for my R2 bucket, but getting the above error when getSignedUrl is executed.
const R2_URL = `https://${ctx.env.ACCOUNT_ID}.r2.cloudflarestorage.com`
const s3Client = new S3Client({
region: "auto",
endpoint: R2_URL,
credentials: {
accessKeyId: ctx.env.ACCESS_KEY_ID,
secretAccessKey: ctx.env.ACCESS_KEY,
},
})
const objectKey = `${app.slug}/${input.name}`
const cmd = new PutObjectCommand({
Bucket: ctx.env.BUCKET_NAME,
Key: objectKey,
})
const signedUrl = await getSignedUrl(s3Client, cmd, { expiresIn: 3600 })
const R2_URL = `https://${ctx.env.ACCOUNT_ID}.r2.cloudflarestorage.com`
const s3Client = new S3Client({
region: "auto",
endpoint: R2_URL,
credentials: {
accessKeyId: ctx.env.ACCESS_KEY_ID,
secretAccessKey: ctx.env.ACCESS_KEY,
},
})
const objectKey = `${app.slug}/${input.name}`
const cmd = new PutObjectCommand({
Bucket: ctx.env.BUCKET_NAME,
Key: objectKey,
})
const signedUrl = await getSignedUrl(s3Client, cmd, { expiresIn: 3600 })
2 replies
CDCloudflare Developers
Created by Ahmed Eid on 10/31/2024 in #workers-help
database connection doesn't work in / behave strangely in global context.
this doesn't work
const db = new Kysely<DB>({
dialect: new PostgresDialect({ pool: new Pool({ connectionString }) }),
});

app.get("/", async (c) => {
const langs = await db.selectFrom("Language").selectAll().executeTakeFirst();
return c.json(langs);
});
const db = new Kysely<DB>({
dialect: new PostgresDialect({ pool: new Pool({ connectionString }) }),
});

app.get("/", async (c) => {
const langs = await db.selectFrom("Language").selectAll().executeTakeFirst();
return c.json(langs);
});
this however does work fine.
app.get("/", async (c) => {
const db = new Kysely<DB>({
dialect: new PostgresDialect({ pool: new Pool({ connectionString }) }),
});
const langs = await db.selectFrom("Language").selectAll().executeTakeFirst();
return c.json(langs);
});
app.get("/", async (c) => {
const db = new Kysely<DB>({
dialect: new PostgresDialect({ pool: new Pool({ connectionString }) }),
});
const langs = await db.selectFrom("Language").selectAll().executeTakeFirst();
return c.json(langs);
});
both work fine in lambdas. what's happening ?
9 replies
CDCloudflare Developers
Created by Ahmed Eid on 10/25/2024 in #general-help
my worker is throwing too many, error 1101.
I am migrating from Lambda, I was using this code
import pg from "pg"
import { Kysely, ParseJSONResultsPlugin, PostgresDialect } from "kysely"

import type { DB } from "../../db/src"

const { Pool } = pg

const globaldb = global as unknown as { db: Kysely<DB> }

export const db =
globaldb.db ||
new Kysely<DB>({
dialect: new PostgresDialect({ pool: new Pool({ connectionString: process.env.DATABASE_URL }) }),
plugins: [new ParseJSONResultsPlugin()],
})

if (process.env.NODE_ENV !== "production") {
globaldb.db = db
}
import pg from "pg"
import { Kysely, ParseJSONResultsPlugin, PostgresDialect } from "kysely"

import type { DB } from "../../db/src"

const { Pool } = pg

const globaldb = global as unknown as { db: Kysely<DB> }

export const db =
globaldb.db ||
new Kysely<DB>({
dialect: new PostgresDialect({ pool: new Pool({ connectionString: process.env.DATABASE_URL }) }),
plugins: [new ParseJSONResultsPlugin()],
})

if (process.env.NODE_ENV !== "production") {
globaldb.db = db
}
but in case of my worker, one request works & the other does not, not sure what's wrong here.
24 replies