V2EX = way to explore
V2EX 是一个关于分享和探索的地方
Sign Up Now
For Existing Member  Sign In
爱意满满的作品展示区。
jswh

初学 ts,写了个玩具 - yet another toy typescript framework

  •  
  •   jswh · Dec 14, 2016 · 2907 views
    This topic created in 3421 days ago, the information mentioned may be changed or developed.

    一直很喜欢 flask 的路由写法,看到 TS 也有 decorator 就搞了一个。

    import {Router, HttpRequest, BaseController} from "yattsf"
    
    export class HelloController extends BaseController {
          @Router.get('/')
          hello(req:HttpRequest) {
              return 'hello';
          }
    }
    
    Supplement 1  ·  Dec 14, 2016
    3 replies    2016-12-14 12:01:01 +08:00
    EPr2hh6LADQWqRVH
        1
    EPr2hh6LADQWqRVH  
       Dec 14, 2016
    我也写了一个,不过是基于 koa

    ```
    import { RouteHost, Middleware, Controller, ExtendedContext, NextCallback, RouteHub } from 'petropub-dev-lib';

    export class HelloWorldBaseRoutes extends RouteHost {

    @Middleware('/666', { restrict: undefined })
    helloWorld__(ctx: ExtendedContext, next: NextCallback) {
    ctx.body += '333';
    return next();
    }

    };

    export class HelloWorldRoutes extends HelloWorldBaseRoutes {

    @Controller('GET', '/666')
    helloWorld(ctx: ExtendedContext, next: NextCallback) {
    ctx.body += '6666';
    return next();
    }
    @Middleware('/666', { restrict: undefined })
    helloWorld_(ctx: ExtendedContext, next: NextCallback) {
    ctx.body += '5555';
    return next();
    }

    };

    let theHelloWorldHub = new RouteHub();
    new HelloWorldRoutes(theHelloWorldHub);

    export { theHelloWorldHub }
    ```
    jswh
        2
    jswh  
    OP
       Dec 14, 2016
    @avastms 😝
    jswh
        3
    jswh  
    OP
       Dec 14, 2016
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Solana   ·   3190 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 29ms · UTC 00:25 · PVG 08:25 · LAX 17:25 · JFK 20:25
    ♥ Do have faith in what you're doing.