andrijan
andrijan
Explore posts from servers
CDCloudflare Developers
Created by andrijan on 4/12/2025 in #pages-help
Turborepo React Vite: build output directory contains links to files that can't
Hi, I am getting the following error after a succesful build of my frontend app: 22:02:18.072 Failed: build output directory contains links to files that can't be accessed I believe it is related to pnpm having symlinks to the packages in node_modules. Should I be updating the build process or is there a workaround? I looked for answers online, but there are no guides for this. There was an issue on GitHub, but it was closed without a resolution.
1 replies
DTDrizzle Team
Created by andrijan on 8/21/2023 in #help
Instantiate a connection with PlanetScale in Cloudflare Workers
Hey, What would be the right way to instantiate a database connection with PlanetScale in Cloudflare workers and reuse it across different handlers? We cannot instantiate it outside the handler because we have no access to the environment variables :
const connection = connect({
url: ENV,
fetch: (url, init) => {
delete init["cache"];
return fetch(url, init);
},
});

const db = drizzle(connection);

app.get("/users", async () => ...);
const connection = connect({
url: ENV,
fetch: (url, init) => {
delete init["cache"];
return fetch(url, init);
},
});

const db = drizzle(connection);

app.get("/users", async () => ...);
So, we need to create a function where we can pass the env object as a parameter to access the environment variables:
export function db(env: ENV_VARIABLES) {
const connection = connect({
url: env.DATABASE_URL,
fetch: (url, init) => {
delete init["cache"];
return fetch(url, init);
},
});

return drizzle(connection);
}
export function db(env: ENV_VARIABLES) {
const connection = connect({
url: env.DATABASE_URL,
fetch: (url, init) => {
delete init["cache"];
return fetch(url, init);
},
});

return drizzle(connection);
}
And then use it in different handlers:
app.post("/users", async (context) => db.insert(users).values({...});
app.post("/posts", async (context) => db.insert(posts).values({...});
app.post("/users", async (context) => db.insert(users).values({...});
app.post("/posts", async (context) => db.insert(posts).values({...});
I wonder if this is a safe way to instantiate a connection and reuse it across different handlers with Cloudflare Workers?
2 replies