Controller配置指南
SugarServer中路由都是通过装饰的方式配置的。
例子
import {Controller,router} from 'sugar-server';export class HelloWorldController extends Controller {@router.GetRoute('/')home () {return 'hello World!';}
@router.GetRoute('/')
这行装饰器就完成路由配置,后面只要使用该controller就好了
支持的请求 method
GetRoute响应method=GET的请求PostRoute响应method=POST的请求PutRoute响应method=PUT的请求DelRoute响应method=DELETE的请求AllRoute响应所有method类型的请求
高阶使用
装饰器的良好特性,可以支持一个函数上同时使用多个装饰
@router.GetRoute('/hello-word')@router.GetRoute('/hello-word-2')home () {return 'hello World!';}
这样不管你访问 /hello-word 还是 /hello-word-2都能看到 hello World!
