Skip to content

Commit

Permalink
Fix empty-body bug
Browse files Browse the repository at this point in the history
  • Loading branch information
Meldiron committed Jan 20, 2023
1 parent e5136ba commit f28ed79
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 3 deletions.
10 changes: 8 additions & 2 deletions deno/send_http_request/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -41,19 +41,25 @@ $ cd deno/send_http_request
2. Enter this function folder and build the code:

```
docker run -e INTERNAL_RUNTIME_ENTRYPOINT=mod.ts --rm --interactive --tty --volume $PWD:/usr/code openruntimes/deno:v2-1.24 sh /usr/local/src/build.sh
docker run -e INTERNAL_RUNTIME_ENTRYPOINT=src/mod.ts --rm --interactive --tty --volume $PWD:/usr/code openruntimes/deno:v2-1.24 sh /usr/local/src/build.sh
```

As a result, a `code.tar.gz` file will be generated.

3. Start the Open Runtime:

```
docker run -p 3000:3000 -e INTERNAL_RUNTIME_ENTRYPOINT=mod.ts -e INTERNAL_RUNTIME_KEY=secret-key --rm --interactive --tty --volume $PWD/code.tar.gz:/tmp/code.tar.gz:ro openruntimes/deno:v2-1.24 sh /usr/local/src/start.sh
docker run -p 3000:3000 -e INTERNAL_RUNTIME_ENTRYPOINT=src/mod.ts -e INTERNAL_RUNTIME_KEY=secret-key --rm --interactive --tty --volume $PWD/code.tar.gz:/tmp/code.tar.gz:ro openruntimes/deno:v2-1.24 sh /usr/local/src/start.sh
```

Your function is now listening on port `3000`, and you can execute it by sending `POST` request with appropriate authorization headers. To learn more about runtime, you can visit Deno runtime [README](https://github.com/open-runtimes/open-runtimes/tree/main/runtimes/deno-1.14).

4. Execute function:

```shell
curl http:https://localhost:3000/ -d '{"payload": "{\"url\":\"https://demo.appwrite.io/v1/locale/countries/eu\",\"method\":\"GET\",\"headers\":{\"x-client-version\":\"1.0.0\"}}"}' -H "X-Internal-Challenge: secret-key" -H "Content-Type: application/json"
```

## 📝 Notes

- This function is designed for use with Appwrite Cloud Functions. You can learn more about it in [Appwrite docs](https://appwrite.io/docs/functions).
Expand Down
2 changes: 1 addition & 1 deletion deno/send_http_request/src/mod.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ export default async function (req: any, res: any) {
throw new Error("method is required");
}

const response = await fetch(url, { method, headers, body: JSON.stringify(body) });
const response = await fetch(url, { method, headers, body: body ? JSON.stringify(body) : undefined });

if (response.status !== 200) {
res.json({ success: false, message: "URL could not be reached." });
Expand Down

0 comments on commit f28ed79

Please sign in to comment.