deno.land / x / alosaur@v1.1.1 / examples / hooks / areas / home.area.ts

نووسراو ببینە
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
import { ActionParam, Area, BadRequestError, Body, Controller, Get, Post, UseHook } from "alosaur/mod.ts";
import { TokenHook } from "../hooks/token-hook.ts";import { CatchHook } from "../hooks/catch-hook.ts";import { PreHook } from "../hooks/pre-hook.ts";import { AsyncPreHook } from "../hooks/async-pre-hook.ts";import { PostHook } from "../hooks/post-hook.ts";import { Authorize } from "../decorators/authorize-hook.decorator.ts";
@Controller()export class HomeController { @Get("/") text() { return `main page`; }
@UseHook(AsyncPreHook) @Get("/await") awaitText() { return `await page`; }
@UseHook(TokenHook, "123") @UseHook(PreHook) @Get("/many-hook-1") many1Hook() { return "many hook 1 page"; }
@UseHook(PreHook) @UseHook(TokenHook, "123") @Get("/many-hook-2") many2Hook() { return "many hook 2 page"; }
@UseHook(TokenHook, "123") @Get("/error") geterror() { throw new BadRequestError(); }
@UseHook(CatchHook) @Get("/error-hook") geterrorhook() { throw new BadRequestError(); }
@UseHook(PostHook) @Post("/post-hook") @ActionParam(0, Body) getposthook(body: any) { return body; }
@Authorize("admin") @Get("/protected") getAdminPage() { return "Hi! this protected info"; }}
@Area({ controllers: [HomeController],})export class HomeArea {}
alosaur

Version Info

Tagged at
a year ago