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 new file mode 100644 index 0000000..e8488a6 --- /dev/null +++ b/deno/README.md @@ -0,0 +1,23 @@ +# Deno Example + +This repository contains an example of Deno application that is deployed on Dokploy. + + +1. **Use Git Provider in Your Application**: + - 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. + +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. + + +If you need further assistance, join our [Discord server](https://discord.com/invite/2tBnJ3jDJc). diff --git a/deno/deno.json b/deno/deno.json new file mode 100644 index 0000000..7918003 --- /dev/null +++ b/deno/deno.json @@ -0,0 +1,11 @@ +{ + "tasks": { + "dev": "deno run --watch main.ts", + "start": "deno run --allow-read --allow-env --allow-net main.ts" + }, + "imports": { + "@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/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/public/index.html b/deno/public/index.html new file mode 100644 index 0000000..521951a --- /dev/null +++ b/deno/public/index.html @@ -0,0 +1,40 @@ + + + + + + + Deno 2 Web Server + + + +
+

Welcome to Deno 2

+

Your Deno 2 web server is up and running!

+

+ Visit the /greet endpoint to see a greeting + message. +

+
+ +