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
TtRPC
Created by Ahmed Eid on 9/20/2024 in #❓-help
when using utils.x.y.getData, is there a way to get when the query was fetch / last updated ?
when using utils.x.y.getData, is there a way to get when the query was fetch / last updated ?
2 replies
HHono
Created by Ahmed Eid on 4/13/2024 in #help
Is there a way to list all request headers ?
I have this use case where I am not sure which header key is being sent, I would like to log all headers to understand more about it.
2 replies
TtRPC
Created by Ahmed Eid on 9/11/2023 in #❓-help
Replacing the dot notation in URLs with forward slash `/` ?
is there a way to replace the dot separation with a forward slash instead ?
so instead of /api/trpc/post.byId it would be /api/trpc/post/byId
1 replies
TtRPC
Created by Ahmed Eid on 8/20/2023 in #❓-help
Nested procedures are separated by dots, is there a way to change that to `/`s instead ?
currently it looks something like this /api/trpc/post.byId, is there a way to have it like /api/trpc/post/byId ?
1 replies
TtRPC
Created by Ahmed Eid on 8/19/2023 in #❓-help
Is there a way to split a trpc api across multiple lambdas ?
How do I go about splitting my TRPC api across multiple lambdas, such that each lambda would load the minimum code it needs to run, (ideally the frontend should not be affected )
20 replies
TtRPC
Created by Ahmed Eid on 6/4/2023 in #❓-help
Subscriptions
are we able to send data over with subscriptions, to allow for full duplex communication ?
2 replies
TtRPC
Created by Ahmed Eid on 12/27/2022 in #❓-help
subscription
13 replies
TtRPC
Created by Ahmed Eid on 10/10/2022 in #❓-help
somehow when move typed function out of the router files, frontend infer type to be any ?
this is inferred corrected since they are in the same file.
getX: t.procedure.query(() => {
return getX()
})

function getX(): X{
...
}
getX: t.procedure.query(() => {
return getX()
})

function getX(): X{
...
}
getX: t.procedure.query(() => {
return getX()
})

export function getX(): X{ << moving this out of the file breaks the typing.
...
}
getX: t.procedure.query(() => {
return getX()
})

export function getX(): X{ << moving this out of the file breaks the typing.
...
}
9 replies
TtRPC
Created by Ahmed Eid on 9/24/2022 in #❓-help
Are there any example of subscriptions working with react native ?
queries and mutations are working pretty well with react native, I'm unable however to get subscriptions to work.
1 replies
TtRPC
Created by Ahmed Eid on 9/21/2022 in #❓-help
when throwing a TRPCError, is there a way to include an internal error code ?
3 replies
TtRPC
Created by Ahmed Eid on 9/20/2022 in #❓-help
extra json property added after data when consuming a query hook.
28 replies