Skip to content

Commit 334891b

Browse files
committed
Fix code block
1 parent 3ffbcaf commit 334891b

File tree

1 file changed

+45
-45
lines changed

1 file changed

+45
-45
lines changed

src/content/docs/learning-paths/holistic-ai-security/appendix/workers-create-custom-coaching-pages.mdx

Lines changed: 45 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -8,39 +8,39 @@ sidebar:
88

99
Cloudflare Workers are an easy method to stand up custom user coaching pages. The customs status pages can be handled dynamically based on the information that Gateway sends about a blocked request.
1010

11-
## Example
11+
## Example
1212

13-
```
13+
```js
1414
const COMPANY_NAME = "Your Company Inc.";
15-
const APPROVED_TOOL_URL = 'https://chat.yourcompany.com'; // Your sanctioned AI tool URL
16-
const APPROVED_TOOL_NAME = 'Corporate AI Assistant'; // The user-friendly name of your tool
17-
const IT_HELPDESK_EMAIL = '[email protected]'; // Email for the "report a problem" button
18-
const COMPANY_LOGO_URL = 'Your_Logo.svg'; // A publicly accessible URL for your company logo. Replace with your own.
15+
const APPROVED_TOOL_URL = "https://chat.yourcompany.com"; // Your sanctioned AI tool URL
16+
const APPROVED_TOOL_NAME = "Corporate AI Assistant"; // The user-friendly name of your tool
17+
const IT_HELPDESK_EMAIL = "[email protected]"; // Email for the "report a problem" button
18+
const COMPANY_LOGO_URL = "Your_Logo.svg"; // A publicly accessible URL for your company logo. Replace with your own.
1919

2020
export default {
21-
async fetch(request) {
22-
// 1. Get the blocked URL from the query string passed by Gateway.
23-
const url = new URL(request.url);
24-
const blockedUrlParam = url.searchParams.get('blocked_url');
21+
async fetch(request) {
22+
// 1. Get the blocked URL from the query string passed by Gateway.
23+
const url = new URL(request.url);
24+
const blockedUrlParam = url.searchParams.get("blocked_url");
2525

26-
// Decode and sanitize the blocked URL for display.
27-
let blockedHostname = "the requested site";
28-
let fullBlockedUrl = "an unapproved external tool";
29-
if (blockedUrlParam) {
30-
try {
31-
const decodedUrl = decodeURIComponent(blockedUrlParam);
32-
fullBlockedUrl = decodedUrl;
33-
blockedHostname = new URL(decodedUrl).hostname;
34-
} catch (e) {
35-
// If the URL is malformed, use the raw param safely.
36-
fullBlockedUrl = blockedUrlParam;
37-
blockedHostname = blockedUrlParam;
38-
}
39-
}
26+
// Decode and sanitize the blocked URL for display.
27+
let blockedHostname = "the requested site";
28+
let fullBlockedUrl = "an unapproved external tool";
29+
if (blockedUrlParam) {
30+
try {
31+
const decodedUrl = decodeURIComponent(blockedUrlParam);
32+
fullBlockedUrl = decodedUrl;
33+
blockedHostname = new URL(decodedUrl).hostname;
34+
} catch (e) {
35+
// If the URL is malformed, use the raw param safely.
36+
fullBlockedUrl = blockedUrlParam;
37+
blockedHostname = blockedUrlParam;
38+
}
39+
}
4040

41-
// 2. Prepare the "Report a problem" mailto link.
42-
const mailtoSubject = Business Justification for AI Tool: ${blockedHostname};
43-
const mailtoBody = `Hello IT/Security Team,
41+
// 2. Prepare the "Report a problem" mailto link.
42+
const mailtoSubject = `Business Justification for AI Tool: ${blockedHostname}`;
43+
const mailtoBody = `Hello IT/Security Team,
4444
4545
I was attempting to access the following website and was redirected to this coaching page:
4646
${fullBlockedUrl}
@@ -51,29 +51,29 @@ My business justification for needing this specific tool is:
5151
Thank you,
5252
[Your Name]`;
5353

54-
const mailtoLink = mailto:${IT_HELPDESK_EMAIL}?subject=${encodeURIComponent(mailtoSubject)}&body=${encodeURIComponent(mailtoBody)};
54+
const mailtoLink = `mailto:${IT_HELPDESK_EMAIL}?subject=${encodeURIComponent(mailtoSubject)}&body=${encodeURIComponent(mailtoBody)}`;
5555

56-
// 3. Generate the full HTML page.
57-
const html = generateHTML(blockedHostname, mailtoLink);
56+
// 3. Generate the full HTML page.
57+
const html = generateHTML(blockedHostname, mailtoLink);
5858

59-
// 4. Return the HTML as a response.
60-
return new Response(html, {
61-
headers: {
62-
'Content-Type': 'text/html;charset=UTF-8',
63-
},
64-
});
65-
},
59+
// 4. Return the HTML as a response.
60+
return new Response(html, {
61+
headers: {
62+
"Content-Type": "text/html;charset=UTF-8",
63+
},
64+
});
65+
},
6666
};
6767

6868
/**
69-
* Generates the full HTML for the coaching page.
70-
* @param {string} blockedHostname - The hostname of the site the user tried to access.
71-
* @param {string} mailtoLink - The pre-built mailto link for reporting an issue.
72-
* @returns {string} - The complete HTML document as a string.
73-
*/
69+
* Generates the full HTML for the coaching page.
70+
* @param {string} blockedHostname - The hostname of the site the user tried to access.
71+
* @param {string} mailtoLink - The pre-built mailto link for reporting an issue.
72+
* @returns {string} - The complete HTML document as a string.
73+
*/
7474
function generateHTML(blockedHostname, mailtoLink) {
75-
// Using a template literal for easy-to-read HTML with embedded variables.
76-
return `
75+
// Using a template literal for easy-to-read HTML with embedded variables.
76+
return `
7777
<!DOCTYPE html>
7878
<html lang="en">
7979
<head>
@@ -202,4 +202,4 @@ We encourage you to use our officially approved and secure solution, the
202202

203203
If successful, your custom user coaching page will look like the image below. It will appear anytime a user attempts to access an unapproved AI tool.
204204

205-
![Exmaple of a custom coaching page utilizing the code example above.](~/assets/images/learning-paths/holistic-ai-security/custom-coaching-page.png)
205+
![Example of a custom coaching page utilizing the code example above.](~/assets/images/learning-paths/holistic-ai-security/custom-coaching-page.png)

0 commit comments

Comments
 (0)