x-custom-token
的值,若其值等于 token-123456 则允许访问,否则拒绝访问。使用边缘函数实现了简单的权限控制。async function handleRequest(request) {const token = request.headers.get('x-custom-token');if (token === 'token-123456') {return new Response('hello world');}// Incorrect key supplied. Reject the request.return new Response('Sorry, you have supplied an invalid token.', {status: 403,});}addEventListener('fetch', event => {event.respondWith(handleRequest(event.request));});
本页内容是否解决了您的问题?