D
Deno

help

Fetch request from own server

Rruaan1/31/2024
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?
DAHDeno AI Helper1/31/2024
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
DAHDeno AI Helper1/31/2024
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. 🦕
ASAntonio Sampaio1/31/2024
do you receive any errors?
EEsente1/31/2024
Deploy does not allow fetching itself to prevent loop.
ASAntonio Sampaio1/31/2024
huuum nice, didnt know that
Rruaan1/31/2024
how can i keep the server from going idle them?
EEsente1/31/2024
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.
ASAntonio Sampaio1/31/2024
what is your objective? maybe we can help you achieve
EEsente2/1/2024
Technically, you maybe to use Deno.cron to keep your isolate alive.
Rruaan2/1/2024
how using deno.cron would keep it alive?
EEsente2/1/2024
You can have a "ping" job that runs every minute, and it will ensure there is an isolate running for your project.
Rruaan2/1/2024
^ 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?
EEsente2/1/2024
Without your objective, it's hard to see.
EEsente2/1/2024
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.
Ccknight2/2/2024
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.

Looking for more? Join the community!

Recommended Posts
Service keep restartingTwo GitHub projects, prod and customer are created using Deno for data syncing. Both projects are hRun `nvm` using Deno.CommandHello, I am trying to run `nvm` from a Deno script using Deno.Command. ```ts new Deno.Command('nvmCreating custom GitHub Action using DenoHey, I am currently trying to develop my first own custom GitHub Action. I have some trouble settinghow to avoid deprecation warnings in compiled binaries```sh $ pkgx --version warning: Use of deprecated "Deno.stderr.rid" API. This API will be removed inDeno compile with "--no-terminal" don't workI'm trying to compile a very simple file named main.ts ```ts await Deno.writeTextFile('test.txt', 'Hdeno task start not runnning in Powershell.This is the link of the tutorial I am following https://github.com/googleanalytics/ga4-tutorials?tabDeployment ID not available after API deploymentHi - i'm calling the /deployments endpoint after creating a new project: ${API}/projects/${project.`Request` body reading functions: possible error types[This](https://docs.deno.com/runtime/manual/runtime/http_server_apis#inspecting-the-incoming-requestHow to call a JS function from Rust?Hi, I'd like to call a JS function from Rust but I can't seem to find an example that does so. I goView code in Subhosting projectHi there - i'm using the API to create a new project and deployment with Subhosting. Just wondering Stop deno deploy instanceHi everyone, I just deployed my first test deno project on deno deploy. Now I'm wondering how to stoHow can I flush a stream to a response?I'm trying to stream a response but it appears that data is only sent after either a newline is writHoping for a clean way to get an array of filenames in directoryTrying to do something like this: ```typescript const files = Deno.readDirSync(Deno.cwd()).map(x => Support for auto-accessorsI'm playing around with Decorators, it seems like with `"experimentalDecorators": false`, there's a Rust sdk register_actity_typeHey, I am using the core_sdk in rust. I registered an activity, which should be able to consume follIs there a feature allowing custom "Allow?" CLI inputs?For example, if you `deno run` some program that reads from the file system, you're prompted `Deno r"deno compile --no-terminal" is not workingI'm trying to compile a very simple file named main.ts ```ts await Deno.writeTextFile('test.txt', 'HUsing fresh inside an existing deno folderI have an existing deno project with deno.jsonc at the root and would like to add a web app as a subRemove Dependencies from `deno.lock` fileHello, Somewhere in the code, I did `import postgres from npm:postgres`. This import is the writtenGood scripts/tools to automate conversion of Node.js based projects to Deno?I'm wondering if there are commendations for tools like this? (I found something like this, but it