Skip to content

Commit

Permalink
added predix example file
Browse files Browse the repository at this point in the history
  • Loading branch information
Marguelgtz committed May 22, 2020
1 parent 983db32 commit 209c09c
Showing 1 changed file with 39 additions and 0 deletions.
39 changes: 39 additions & 0 deletions examples/routePrefix.ts
@@ -0,0 +1,39 @@
import {
Application,
Router,
} from "../mod.ts";
const router = new Router({
prefix: "/prefix",
// strict: true,
});

const port = 4000;

const server = new Application();

server.use(
router.routes(),
router.allowedMethods(),
);

router
.get("/", ({ response }: { response: any }) => {
response.status = 200;
response.body = { msg: "Prefix works" };
})
.get(
"/:id",
({ params, response }: { params: { id: string }; response: any }) => {
response.body = `prefix w/ id: ${params.id}`;
},
)
.get(
"/test",
({ params, response }: { params: { id: string }; response: any }) => {
response.body = `test`;
},
);

console.log("server running");

await server.listen({ port });

0 comments on commit 209c09c

Please sign in to comment.