mattp
mattp
Explore posts from servers
CDCloudflare Developers
Created by mattp on 9/16/2024 in #workers-help
How to cache worker response?
I want to cache worker response, so that when the next request comes in, there will be no worker invocation.
8 replies
CDCloudflare Developers
Created by mattp on 7/1/2024 in #workers-help
Is worker binding call included in Cloudflare REST API rate limits?
https://developers.cloudflare.com/fundamentals/api/reference/limits/ according to this doc, I can't tell if it counts or not. what about wrangler kv commands?
4 replies
HHono
Created by mattp on 6/13/2024 in #help
@hono/zod-openapi: How to write OpenAPI doc for middleware responses?
I have an auth middleware which will check if the api token is provided in the request header, so it will respond with 401 or pass. How to make sure every protected route will be applied with the 401 response?
app.openapi(
createRoute({
middleware: [auth],
method: 'get',
path: '/my-endpoint',
security: [{ Authorization: [] }],
request: {
// ...
},
responses: {
200: {
// ...
},
// 401
},
}),
async (ctx) => {
// do something
}
)
app.openapi(
createRoute({
middleware: [auth],
method: 'get',
path: '/my-endpoint',
security: [{ Authorization: [] }],
request: {
// ...
},
responses: {
200: {
// ...
},
// 401
},
}),
async (ctx) => {
// do something
}
)
2 replies
CDCloudflare Developers
Created by mattp on 2/2/2024 in #workers-help
How to seed local KV (.wrangler/state)?
I can use the wrangler kv:bulk put to seed prod/preview KV, but how to seed local KV?
3 replies
CDCloudflare Developers
Created by mattp on 10/17/2023 in #workers-help
Download KV record in bulk
Any way to download kv store record in bulk? I mean save as a local file.
3 replies
CDCloudflare Developers
Created by mattp on 9/21/2023 in #workers-help
Can I have route trigger only on local development?
Something like:
export default {
scheduled: myScheduledJob,
...( DEV && { fetch: myDevHandlers } )
}
export default {
scheduled: myScheduledJob,
...( DEV && { fetch: myDevHandlers } )
}
5 replies
CDCloudflare Developers
Created by mattp on 7/31/2023 in #pages-help
How to add KV binding to Qwik City project in local development?
I create my qwik city project with pnpm create cloudflare@latest, and I follow this instruction: https://developers.cloudflare.com/pages/framework-guides/deploy-a-qwik-site/#use-bindings-in-your-qwik-application my package.json:
{
"scripts": {
"pages:dev": "wrangler pages dev --kv=MY_KV -- pnpm run dev",
"dev": "vite --mode ssr"
}
}
{
"scripts": {
"pages:dev": "wrangler pages dev --kv=MY_KV -- pnpm run dev",
"dev": "vite --mode ssr"
}
}
$ pnpm pages:dev
$ pnpm pages:dev
// src/routes/index.tsx
export const useData = routeLoader$(({ platform }) => {
console.log((platform as (typeof platform & { MY_KV: KVNamespace })).MY_KV); // undefined
return [];
});
// src/routes/index.tsx
export const useData = routeLoader$(({ platform }) => {
console.log((platform as (typeof platform & { MY_KV: KVNamespace })).MY_KV); // undefined
return [];
});
The MY_KV is not in platform
3 replies
CDCloudflare Developers
Created by mattp on 4/14/2023 in #workers-help
Incorrect type for Promise: the Promise did not resolve to 'Response'.
I'm using the itty-router for routing
export default {
fetch: async (request: Request, env: Env, context: Context) => {
context.slack = new Slack(env.SLACK_APP_BOT_TOKEN);
context.waitUntil(router.handle(request, env, context));
},
};
export default {
fetch: async (request: Request, env: Env, context: Context) => {
context.slack = new Slack(env.SLACK_APP_BOT_TOKEN);
context.waitUntil(router.handle(request, env, context));
},
};
3 replies
CDCloudflare Developers
Created by mattp on 3/21/2023 in #pages-help
How to make Next.js i18n routing work with Pages?
I use this command to build my Next.js project:
pnpm dlx @cloudflare/next-on-pages
pnpm dlx @cloudflare/next-on-pages
And deploy:
CLOUDFLARE_ACCOUNT_ID=38bc8e8ffacb44cf6ab6293124ef8e28 wrangler pages publish .vercel/output/static
CLOUDFLARE_ACCOUNT_ID=38bc8e8ffacb44cf6ab6293124ef8e28 wrangler pages publish .vercel/output/static
My next config:
{
reactStrictMode: true,
i18n: {
locales: ['en', 'zh-TW'],
defaultLocale: 'en',
},
trailingSlash: true,
}
{
reactStrictMode: true,
i18n: {
locales: ['en', 'zh-TW'],
defaultLocale: 'en',
},
trailingSlash: true,
}
3 replies
CDCloudflare Developers
Created by mattp on 2/9/2023 in #workers-help
What's the difference between `--local` & `--test-scheduled` for local development?
I use wrangler (v2.9) to initialize my worker project (a scheduled worker). The top message in the index.ts file says: Run wrangler dev --local in your terminal to start a development server But in this doc (https://developers.cloudflare.com/workers/runtime-apis/scheduled-event/) it says: wrangler dev --test-scheduled So what's the difference? workers
2 replies