From 818be08214e8b93e2f7b50d883be95486e4f0a7b Mon Sep 17 00:00:00 2001 From: Mauricio Siu <47042324+Siumauricio@users.noreply.github.com> Date: Sun, 23 Feb 2025 20:13:56 -0600 Subject: [PATCH] chore: Set up Deno project with Docker, environment configuration, and basic server --- deno/Dockerfile | 15 +++++++++++ deno/README.md | 5 ++-- deno/deno.json | 6 +++-- deno/deno.lock | 59 ++++++++++++++++++++++++++++++++++++++++++ deno/index.ts | 10 ------- deno/main.ts | 24 +++++++++++++++++ deno/main_test.ts | 6 ----- deno/public/index.html | 2 +- 8 files changed, 106 insertions(+), 21 deletions(-) create mode 100644 deno/Dockerfile create mode 100644 deno/deno.lock delete mode 100644 deno/index.ts create mode 100644 deno/main.ts delete mode 100644 deno/main_test.ts diff --git a/deno/Dockerfile b/deno/Dockerfile new file mode 100644 index 0000000..ced095b --- /dev/null +++ b/deno/Dockerfile @@ -0,0 +1,15 @@ +FROM denoland/deno:2.0.1 + +WORKDIR /app + +COPY deno.json . + +RUN deno install + +COPY . . +RUN deno cache main.ts + +ARG PORT=8000 +EXPOSE $PORT + +CMD ["task", "start"] \ No newline at end of file diff --git a/deno/README.md b/deno/README.md index 6e7d4d4..e8488a6 100644 --- a/deno/README.md +++ b/deno/README.md @@ -1,4 +1,3 @@ - # Deno Example This repository contains an example of Deno application that is deployed on Dokploy. @@ -8,7 +7,8 @@ This repository contains an example of Deno application that is deployed on Dokp - Repository: `https://github.com/Dokploy/examples.git` - Branch: `main` - Build path: `/deno` - + - Select `Dockerfile` as Build Type + - Type `Dockerfile` in the Dockerfile path field 2. **Click on Deploy**: - Deploy your application by clicking the deploy button. @@ -16,6 +16,7 @@ This repository contains an example of Deno application that is deployed on Dokp 3. **Generate a Domain**: - Click on generate domain button. - A new domain will be generated for you. + - Set Port `8080` - You can use this domain to access your application. diff --git a/deno/deno.json b/deno/deno.json index 8c2a561..7918003 100644 --- a/deno/deno.json +++ b/deno/deno.json @@ -1,9 +1,11 @@ { "tasks": { "dev": "deno run --watch main.ts", - "build": "deno run build.ts" + "start": "deno run --allow-read --allow-env --allow-net main.ts" }, "imports": { - "@std/assert": "jsr:@std/assert@1" + "@std/assert": "jsr:@std/assert@1", + "@std/dotenv": "jsr:@std/dotenv@^0.225.2", + "@std/http": "jsr:@std/http@^1.0.8" } } diff --git a/deno/deno.lock b/deno/deno.lock new file mode 100644 index 0000000..6d8b05e --- /dev/null +++ b/deno/deno.lock @@ -0,0 +1,59 @@ +{ + "version": "4", + "specifiers": { + "jsr:@std/cli@^1.0.6": "1.0.6", + "jsr:@std/dotenv@*": "0.225.2", + "jsr:@std/encoding@^1.0.5": "1.0.5", + "jsr:@std/fmt@^1.0.2": "1.0.2", + "jsr:@std/http@*": "1.0.8", + "jsr:@std/media-types@^1.0.3": "1.0.3", + "jsr:@std/net@^1.0.4": "1.0.4", + "jsr:@std/path@^1.0.6": "1.0.6", + "jsr:@std/streams@^1.0.7": "1.0.7" + }, + "jsr": { + "@std/cli@1.0.6": { + "integrity": "d22d8b38c66c666d7ad1f2a66c5b122da1704f985d3c47f01129f05abb6c5d3d" + }, + "@std/dotenv@0.225.2": { + "integrity": "e2025dce4de6c7bca21dece8baddd4262b09d5187217e231b033e088e0c4dd23" + }, + "@std/encoding@1.0.5": { + "integrity": "ecf363d4fc25bd85bd915ff6733a7e79b67e0e7806334af15f4645c569fefc04" + }, + "@std/fmt@1.0.2": { + "integrity": "87e9dfcdd3ca7c066e0c3c657c1f987c82888eb8103a3a3baa62684ffeb0f7a7" + }, + "@std/http@1.0.8": { + "integrity": "6ea1b2e8d33929967754a3b6d6c6f399ad6647d7bbb5a466c1eaf9b294a6ebcd", + "dependencies": [ + "jsr:@std/cli", + "jsr:@std/encoding", + "jsr:@std/fmt", + "jsr:@std/media-types", + "jsr:@std/net", + "jsr:@std/path", + "jsr:@std/streams" + ] + }, + "@std/media-types@1.0.3": { + "integrity": "b12d30a7852f7578f4d210622df713bbfd1cbdd9b4ec2eaf5c1845ab70bab159" + }, + "@std/net@1.0.4": { + "integrity": "2f403b455ebbccf83d8a027d29c5a9e3a2452fea39bb2da7f2c04af09c8bc852" + }, + "@std/path@1.0.6": { + "integrity": "ab2c55f902b380cf28e0eec501b4906e4c1960d13f00e11cfbcd21de15f18fed" + }, + "@std/streams@1.0.7": { + "integrity": "1a93917ca0c58c01b2bfb93647189229b1702677f169b6fb61ad6241cd2e499b" + } + }, + "workspace": { + "dependencies": [ + "jsr:@std/assert@1", + "jsr:@std/dotenv@~0.225.2", + "jsr:@std/http@^1.0.8" + ] + } +} diff --git a/deno/index.ts b/deno/index.ts deleted file mode 100644 index 53a5c69..0000000 --- a/deno/index.ts +++ /dev/null @@ -1,10 +0,0 @@ -export function add(a: number, b: number): number { - return a + b; -} - -// Learn more at https://docs.deno.com/runtime/manual/examples/module_metadata#concepts -if (import.meta.main) { - console.log("Add 2 + 3 =", add(2, 3)); -} - -Deno.serve({ hostname: "0.0.0.0", port: 8000 }, () => new Response("Hello, world!")); \ No newline at end of file diff --git a/deno/main.ts b/deno/main.ts new file mode 100644 index 0000000..3062eed --- /dev/null +++ b/deno/main.ts @@ -0,0 +1,24 @@ +import "jsr:@std/dotenv/load"; +import { serveFile } from "jsr:@std/http/file-server"; + +const PORT = Deno.env.get("PORT") || 8000; + +const handler = async (req: Request): Promise => { + const url = new URL(req.url); + + if (url.pathname === "/") { + return await serveFile(req, "./public/index.html"); + } else if (url.pathname === "/greet") { + const greeting = Deno.env.get("GREETING") || "Hello from Deno 2!"; + return new Response(greeting); + } else { + return new Response("Not Found", { status: 404 }); + } +}; + +// Error handling +try { + Deno.serve({ port: Number(PORT) }, handler); +} catch (err) { + console.error("Error starting the server:", err); +} diff --git a/deno/main_test.ts b/deno/main_test.ts deleted file mode 100644 index 721349f..0000000 --- a/deno/main_test.ts +++ /dev/null @@ -1,6 +0,0 @@ -import { assertEquals } from "@std/assert"; -import { add } from "./index.ts"; - -Deno.test(function addTest() { - assertEquals(add(2, 3), 5); -}); diff --git a/deno/public/index.html b/deno/public/index.html index 0a96582..521951a 100644 --- a/deno/public/index.html +++ b/deno/public/index.html @@ -37,4 +37,4 @@

- \ No newline at end of file +