nstcg
CDCloudflare Developers
•Created by nstcg on 8/17/2023 in #workers-help
Can cloudflare domain workers have free SSL ?
Ive made a worker with following index.js
but I couldn't fetch it from a serverless front end html like
when i tried
https://checkforcloudflare.selesti.com/?q=https://hyperbeam.nithinsteven32.workers.dev/
I learned ssl was not setup on the url
maybe that's the issue ?
Any help appreciated 😊
addEventListener('fetch', event => {
event.respondWith(handleRequest(event.request));
});
async function handleRequest(request) {
const response = new Response('helloWorld', {
headers: {
'Content-Type': 'text/plain',
'Access-Control-Allow-Origin': '*', // Replace with your allowed origins
'Access-Control-Allow-Methods': 'GET, POST, OPTIONS', // Allow the necessary methods
},
});
return response;
}
addEventListener('fetch', event => {
event.respondWith(handleRequest(event.request));
});
async function handleRequest(request) {
const response = new Response('helloWorld', {
headers: {
'Content-Type': 'text/plain',
'Access-Control-Allow-Origin': '*', // Replace with your allowed origins
'Access-Control-Allow-Methods': 'GET, POST, OPTIONS', // Allow the necessary methods
},
});
return response;
}
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Cloudflare API Request</title>
</head>
<body>
<button id="fetchButton">Fetch Data</button>
<p id="responseText"></p>
<script>
const fetchButton = document.getElementById('fetchButton');
const responseText = document.getElementById('responseText');
fetchButton.addEventListener('click', async () => {
try {
const response = await fetch('https://hyperbeam.nithinsteven32.workers.dev/');
if (!response.ok) {
throw new Error('Network response was not ok');
}
const data = await response.text();
responseText.textContent = data;
} catch (error) {
console.error('Error fetching data:', error);
responseText.textContent = 'Error fetching data';
}
});
</script>
</body>
</html>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Cloudflare API Request</title>
</head>
<body>
<button id="fetchButton">Fetch Data</button>
<p id="responseText"></p>
<script>
const fetchButton = document.getElementById('fetchButton');
const responseText = document.getElementById('responseText');
fetchButton.addEventListener('click', async () => {
try {
const response = await fetch('https://hyperbeam.nithinsteven32.workers.dev/');
if (!response.ok) {
throw new Error('Network response was not ok');
}
const data = await response.text();
responseText.textContent = data;
} catch (error) {
console.error('Error fetching data:', error);
responseText.textContent = 'Error fetching data';
}
});
</script>
</body>
</html>
2 replies