mirror of
https://github.com/SrIzan10/starters.git
synced 2026-05-01 11:05:16 +00:00
Add deno-oak starter (#214)
This commit is contained in:
5
examples/deno-oak/.gitignore
vendored
Normal file
5
examples/deno-oak/.gitignore
vendored
Normal file
@@ -0,0 +1,5 @@
|
||||
.env
|
||||
.vscode/
|
||||
coverage/
|
||||
cov/
|
||||
lcov/
|
||||
15
examples/deno-oak/Dockerfile
Normal file
15
examples/deno-oak/Dockerfile
Normal file
@@ -0,0 +1,15 @@
|
||||
FROM denoland/deno:1.15.3
|
||||
|
||||
WORKDIR /app
|
||||
|
||||
USER deno
|
||||
|
||||
# Cache deps first
|
||||
ADD deps.ts .
|
||||
RUN deno cache deps.ts
|
||||
|
||||
# These steps will be re-run upon each file change in your working directory:
|
||||
ADD . .
|
||||
RUN deno cache src/index.ts
|
||||
|
||||
CMD deno run --allow-net --allow-env src/index.ts
|
||||
26
examples/deno-oak/README.md
Normal file
26
examples/deno-oak/README.md
Normal file
@@ -0,0 +1,26 @@
|
||||
---
|
||||
title: Deno with Oak
|
||||
description: An example webserver using Oak
|
||||
tags:
|
||||
- typescript
|
||||
---
|
||||
|
||||
# Deno Oak Example
|
||||
|
||||
This example is a small [Deno](https://deno.land/) webserver using [Oak](https://github.com/oakserver/oak) for routing.
|
||||
|
||||
[](https%3A%2F%2Frailway.app%2Fnew%3Ftemplate%3Dhttps%3A%2F%2Fgithub.com%2Frailwayapp%2Fexamples%2Ftree%2Fmaster%2Fexamples%2Fdeno-oak)
|
||||
|
||||
## ✨ Features
|
||||
|
||||
- Deno
|
||||
- TypeScript
|
||||
- Oak Routing
|
||||
## 💁♀️ How to use
|
||||
|
||||
- [Install Deno](https://deno.land/)
|
||||
- Run server `deno run --allow-net --allow-env src/index.ts`
|
||||
|
||||
## 📝 Notes
|
||||
|
||||
This is an experimental example and should not be used in production.
|
||||
1
examples/deno-oak/deps.ts
Normal file
1
examples/deno-oak/deps.ts
Normal file
@@ -0,0 +1 @@
|
||||
export * from "https://deno.land/x/oak@v9.0.1/mod.ts";
|
||||
1
examples/deno-oak/dev_deps.ts
Normal file
1
examples/deno-oak/dev_deps.ts
Normal file
@@ -0,0 +1 @@
|
||||
export {};
|
||||
30
examples/deno-oak/src/index.ts
Normal file
30
examples/deno-oak/src/index.ts
Normal file
@@ -0,0 +1,30 @@
|
||||
import { Application, Router } from "../deps.ts";
|
||||
|
||||
const app = new Application();
|
||||
const port = parseInt(Deno.env.get("PORT") ?? "8000");
|
||||
|
||||
// Router to serve specific functions on routes
|
||||
const router = new Router();
|
||||
|
||||
// Route "ping" that responds with "Pong!"
|
||||
router.get("/ping", ctx => {
|
||||
ctx.response.body = "Pong!";
|
||||
});
|
||||
|
||||
// Example of dynamic routes
|
||||
router.get("/hello/:name", ctx => {
|
||||
ctx.response.body = `Hello ${ctx.params.name}!`;
|
||||
});
|
||||
|
||||
// Apply routes
|
||||
app.use(router.routes());
|
||||
app.use(router.allowedMethods());
|
||||
|
||||
// Basic example with a global route
|
||||
// Applied last, so the router will take precedence
|
||||
app.use(ctx => {
|
||||
ctx.response.body = "Welcome to Railway!";
|
||||
});
|
||||
|
||||
console.log(`Listening on port ${port}...`);
|
||||
await app.listen({ port: port });
|
||||
Reference in New Issue
Block a user