これでIP制限の代わりに国で制限をすることも可能
Workers
worker.js
export default {
async fetch(request, env, ctx) {
const country = request.headers.get('cf-ipcountry');
const message = country
? `The request is from: ${country}`
: 'Could not determine the country.';
return new Response(message);
},
};
Pages & Hono
index.tsx
import { Hono } from 'hono'
const app = new Hono()
app.get('/', async (c) => {
const country = c.req.header('cf-ipcountry');
return c.text(`country: ${country}`);
});
export default app