ruaan
ruaan•10mo ago

Fetch request from own server

try
{
const response = await fetch('.../ping',
{
method: "GET",
headers: {
"Content-Type": "application/json",
},
});
if (!response.ok)
throw new Error('Fetch failed');

console.log(response.ok);
console.log(response.status)
}
catch (error)
{
console.error('Error:', error);
}
try
{
const response = await fetch('.../ping',
{
method: "GET",
headers: {
"Content-Type": "application/json",
},
});
if (!response.ok)
throw new Error('Fetch failed');

console.log(response.ok);
console.log(response.status)
}
catch (error)
{
console.error('Error:', error);
}
why when i make a get request to my own deno deploy server it fails?
15 Replies
Deno AI Helper
Deno AI Helper•10mo ago
When you're making a GET request to your own Deno Deploy server and it fails, there could be several reasons for this. Let's go through some common troubleshooting steps based on the documentation and general advice: 1. Check the URL: Ensure that the URL in the fetch call is correct. The placeholder '.../ping' should be replaced with the actual URL of your server. If you're testing locally, it might be something like 'http://localhost:8000/ping'. 2. Server Response: Verify that your server is correctly handling the route /ping and that it is set up to respond to GET requests with a status code that indicates success (e.g., 200). 3. Content-Type Header: Since you're making a GET request, the "Content-Type": "application/json" header may not be necessary unless your server expects it. However, this should not cause the request to fail. 4. Network Issues: There could be network issues between the client making the request and the server. Ensure that there are no firewalls, proxies, or other network configurations that could be blocking the request. 5. Server Logs: Check the server logs for any errors or stack traces that could provide more information about why the request is failing. 6. Permissions: If you're running the server locally using the Deno CLI, ensure that you have the necessary network permissions. You might need to run your server with the --allow-net flag. 7. Error Handling: Your error handling in the catch block will log any exceptions thrown during the fetch request. Make sure to inspect the error message for clues. 8. Server Code: Review the server-side code to ensure that it's not throwing any errors or failing to handle the request properly. If you've gone through these steps and the issue
Deno AI Helper
Deno AI Helper•10mo ago
persists, you might want to share more details about the server setup, the exact error message you're receiving, and any relevant server-side code. This could help in diagnosing the problem more effectively. 🦕
Antonio Sampaio
Antonio Sampaio•10mo ago
do you receive any errors?
Esente
Esente•10mo ago
Deploy does not allow fetching itself to prevent loop.
Antonio Sampaio
Antonio Sampaio•10mo ago
huuum nice, didnt know that
ruaan
ruaanOP•10mo ago
how can i keep the server from going idle them?
Esente
Esente•10mo ago
You can't. That's not the nature of isolate. It is for being spawned to handle a task and shutdown. It's not a 24/7 hosting platform.
Antonio Sampaio
Antonio Sampaio•10mo ago
what is your objective? maybe we can help you achieve
Esente
Esente•10mo ago
Technically, you maybe to use Deno.cron to keep your isolate alive.
ruaan
ruaanOP•10mo ago
how using deno.cron would keep it alive?
Esente
Esente•10mo ago
You can have a "ping" job that runs every minute, and it will ensure there is an isolate running for your project.
ruaan
ruaanOP•10mo ago
^ i also write this on the first message, it doesn't work sending a request to itself wdym with ping job? fetching from the cron?
Esente
Esente•10mo ago
Without your objective, it's hard to see.
Esente
Esente•10mo ago
Deno Blog
Announcing Deno Cron
Deno.cron allows you to easily create scheduled jobs and is available on Deno Deploy. Here's how it works.
cknight
cknight•10mo ago
cron won't work as there is no guarantee that your isolate will remain active. They can spin down at any time, have multiple running in the same region at any time, etc. It is not possible to keep an isolate up and running for any guaranteed or minimum amount of time. You need to design your service around this aspect which is fundamental to any serverless infra.