Skip to content

youngjuning/duck

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

13 Commits
 
 
 
 
 
 
 
 

Repository files navigation

duck

A simple controller scanner and router register for deno!

Api

duck(router, controller_dir: string = 'controllers')

Usage

oak

export { Application, Context, Router } from "https://deno.land/x/oak/mod.ts";
import duck from "https://deno.land/x/duck/mod.ts";

const app = new Application();
const router = await duck(new Router());

app.use(router.routes());
app.use(router.allowedMethods());

console.log(`🦕 oak server running at http://127.0.0.1:1998/ 🦕`);

await app.listen({ port: 1998 });

Your controllers just like: controllers/helloworld.ts:

import { Context } from "../deps.ts";

export const name = "helloworld";
export const method = "get";

export default async (ctx: Context) => {
  const { response } = ctx;
  response.body = "hello world!";
};