Fetch request from own server
why when i make a get request to my own deno deploy server it fails?
15 Replies
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 issuepersists, 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. 🦕
do you receive any errors?
Deploy does not allow fetching itself to prevent loop.
huuum nice, didnt know that
how can i keep the server from going idle them?
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.
what is your objective? maybe we can help you achieve
Technically, you maybe to use
Deno.cron
to keep your isolate alive.how using deno.cron would keep it alive?
You can have a "ping" job that runs every minute, and it will ensure there is an isolate running for your project.
^
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?
Without your objective, it's hard to see.
But here is the article: https://deno.com/blog/cron#deno-cron-on-deno-deploy
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.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.