Created
September 16, 2016 13:48
-
-
Save dotob/8d58fbed42a6a0850e2bbc91f15c0ed2 to your computer and use it in GitHub Desktop.
Revisions
-
dotob created this gist
Sep 16, 2016 .There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,37 @@ import * as express from 'express'; var app = express(); app.get('/', function (req, res) { res.send('Hello World!'); }); app.listen(3000, function () { console.log('Example app listening on port 3000!'); }); export interface IQueryResult { data: string; } function RouteDecorator(app: express.Application, route: string) { return function ( target: any, propertyKey: string, descriptor: TypedPropertyDescriptor<() =>Promise<IQueryResult>>) { console.log(`create route ${route} for method ${propertyKey}`); app.get(route, async (req, res) => { let r = await target[propertyKey](); res.send(r); }); }; } export class Queries { @RouteDecorator(app, "/a") bla(): Promise<IQueryResult> { return new Promise<IQueryResult>((resolve, reject) => { console.log("bla"); resolve({ data: 'blablablablabla' }); }) } }