chore: Set up Deno project with Docker, environment configuration, and basic server

This commit is contained in:
Mauricio Siu 2025-02-23 20:13:56 -06:00
parent d525138542
commit 818be08214
8 changed files with 106 additions and 21 deletions

15
deno/Dockerfile Normal file
View File

@ -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"]

View File

@ -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.

View File

@ -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"
}
}

59
deno/deno.lock Normal file
View File

@ -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"
]
}
}

View File

@ -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!"));

24
deno/main.ts Normal file
View File

@ -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<Response> => {
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);
}

View File

@ -1,6 +0,0 @@
import { assertEquals } from "@std/assert";
import { add } from "./index.ts";
Deno.test(function addTest() {
assertEquals(add(2, 3), 5);
});

View File

@ -37,4 +37,4 @@
</p>
</div>
</body>
</html>
</html>