tanishq-singh-2407 / deno-file-based-routing

File based routing in deno oak server 🀐

Home Page:https://deno-file-based-routing.deno.dev

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Deno server - file based routing

Overview

This template helps to achive file-based-routing with oak and deno only for creating server.

Index

  1. Tree
  2. Routing
  3. Usage
  4. Licence

Tree

.
β”œβ”€β”€ dev.ts
β”œβ”€β”€ main.ts
β”œβ”€β”€ `src`
β”‚   β”œβ”€β”€ `routes`
β”‚   β”‚   β”œβ”€β”€ index.ts
β”‚   β”‚   β”œβ”€β”€ hlo.ts
β”‚   β”‚   β”œβ”€β”€ `v1`
β”‚   β”‚   β”‚   β”œβ”€β”€ index.ts
β”‚   β”‚   β”‚   └── my-name
β”‚   β”‚   β”‚       └── [name].ts
β”‚   β”‚   └── `v2`
β”‚   β”‚       β”œβ”€β”€ index.ts
β”‚   β”‚       β”œβ”€β”€ kaju.ts
β”‚   β”‚       └── my-name
β”‚   β”‚           β”œβ”€β”€ index.ts
β”‚   β”‚           └── [name].ts
β”‚   └── `database`
β”‚       └── dummy.json
β”œβ”€β”€ `types`
β”‚   └── routes.ts
β”œβ”€β”€ deno.json
β”œβ”€β”€ import_map.json
β”œβ”€β”€ routes.ts

Routing

  • When a file is added to the src/routes directory, it's automatically available as a route.

  • The files inside the src/routes directory can be used to define most common patterns.

  1. Index soutes

    • The router will automatically route files named index to the root of the directory.
    • src/routes/index.ts β†’ /
    • src/routes/blog/index.ts β†’ /blog
  2. Nested routes

    • The router supports nested files. If you create a nested folder structure, files will automatically be routed in the same way still.
    • src/routes/blog/first-post.ts β†’ /blog/first-post
    • src/routes/dashboard/settings/username.ts β†’ /dashboard/settings/username
  3. Dynamic routes segments

    • To match a dynamic segment, you can use the bracket syntax. This allows you to match named parameters.
    • src/routes/blog/[slug].ts β†’ /blog/:slug (/blog/hello-world)
    • src/routes/[username]/settings.ts β†’ /:username/settings (/foo/settings)

Usage

  1. Development mode.

    deno task dev # or
    deno run --allow-read --allow-write --allow-run --watch=src/ dev.ts
  2. Production mode.

    deno task start # or
    deno run --allow-net main.ts
  3. Generate routes.ts.

    deno task generate-routes # or
    deno run --allow-read --allow-write dev.ts --no-server

LICENCE

About

File based routing in deno oak server 🀐

https://deno-file-based-routing.deno.dev

License:MIT License


Languages

Language:TypeScript 100.0%