A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from https://developers.cloudflare.com/rules/snippets/examples/auth-with-headers/ below:

Auth with headers · Cloudflare Rules docs

Caution when using in production

The example code contains a generic header key and value of X-Custom-PSK and mypresharedkey. To best protect your resources, change the header key and value in the Snippets editor before saving your code.

export default {

async fetch(request) {

/**

* @param {string} PRESHARED_AUTH_HEADER_KEY Custom header to check for key

* @param {string} PRESHARED_AUTH_HEADER_VALUE Hard-coded key value

*/

const PRESHARED_AUTH_HEADER_KEY = "X-Custom-PSK";

const PRESHARED_AUTH_HEADER_VALUE = "mypresharedkey";

const psk = request.headers.get(PRESHARED_AUTH_HEADER_KEY);

if (psk === PRESHARED_AUTH_HEADER_VALUE) {

// Correct preshared header key supplied. Fetch request from origin.

return fetch(request);

}

// Incorrect key supplied. Reject the request.

return new Response("Sorry, you have supplied an invalid key.", {

status: 403,

});

},

};


RetroSearch is an open source project built by @garambo | Open a GitHub Issue

Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo

HTML: 3.2 | Encoding: UTF-8 | Version: 0.7.4