Merge pull request #1848 from soywiz/urlrouter

- Added urlrouter
This commit is contained in:
Masahiro Wakame
2014-03-15 20:35:08 +09:00
3 changed files with 89 additions and 0 deletions

View File

@@ -268,6 +268,7 @@ List of Definitions
* [Underscore.js (Typed)](http://underscorejs.org/) (by [Josh Baldwin](https://github.com/jbaldwin/))
* [Underscore-ko.js](https://github.com/kamranayub/UnderscoreKO) (by [Maurits Elbers](https://github.com/MagicMau))
* [universal-analytics](https://github.com/peaksandpies/universal-analytics) (by [Bart van der Schoor](https://github.com/Bartvds))
* [urlrouter](https://github.com/fengmk2/urlrouter) (by [Carlos Ballesteros Velasco](https://github.com/soywiz))
* [UUID.js](https://github.com/LiosK/UUID.js) (by [Jason Jarrett](https://github.com/staxmanade))
* [Valerie](https://github.com/davewatts/valerie) (by [Howard Richards](https://github.com/conficient))
* [Viewporter](https://github.com/zynga/viewporter) (by [Boris Yankov](https://github.com/borisyankov))

View File

@@ -0,0 +1,19 @@
/// <reference path="urlrouter.d.ts" />
import http = require("http");
import urlrouter = require("urlrouter");
var result = urlrouter((app) => {
app.get('/', (req, res, next) => {
res.end('hello urlrouter');
});
app.get('/user/:id([0-9]+)', (req, res, next) => {
res.end('hello user ' + req.params.id);
});
});
var req: urlrouter.ServerRequest;
var res: urlrouter.ServerResponse;
function next() { }
result(req, res, next);

69
urlrouter/urlrouter.d.ts vendored Normal file
View File

@@ -0,0 +1,69 @@
// Type definitions for urlrouter
// Project: https://github.com/fengmk2/urlrouter
// Definitions by: soywiz <https://github.com/soywiz>
// Definitions: https://github.com/borisyankov/DefinitelyTyped
/// <reference path="../node/node.d.ts" />
declare module "_UrlRouterInternal" {
import http = require("http");
export interface ServerRequest extends http.ServerRequest {
params: any;
}
export interface ServerResponse extends http.ServerResponse {
}
export interface App {
// https://github.com/visionmedia/node-methods/blob/master/index.js
get(urlpattern: string, handler: HttpHandler): void;
post(urlpattern: string, handler: HttpHandler): void;
put(urlpattern: string, handler: HttpHandler): void;
head(urlpattern: string, handler: HttpHandler): void;
delete(urlpattern: string, handler: HttpHandler): void;
options(urlpattern: string, handler: HttpHandler): void;
trace(urlpattern: string, handler: HttpHandler): void;
copy(urlpattern: string, handler: HttpHandler): void;
lock(urlpattern: string, handler: HttpHandler): void;
mkcol(urlpattern: string, handler: HttpHandler): void;
move(urlpattern: string, handler: HttpHandler): void;
propfind(urlpattern: string, handler: HttpHandler): void;
proppatch(urlpattern: string, handler: HttpHandler): void;
unlock(urlpattern: string, handler: HttpHandler): void;
report(urlpattern: string, handler: HttpHandler): void;
mkactivity(urlpattern: string, handler: HttpHandler): void;
checkout(urlpattern: string, handler: HttpHandler): void;
merge(urlpattern: string, handler: HttpHandler): void;
"m-search"(urlpattern: string, handler: HttpHandler): void;
notify(urlpattern: string, handler: HttpHandler): void;
subscribe(urlpattern: string, handler: HttpHandler): void;
unsubscribe(urlpattern: string, handler: HttpHandler): void;
patch(urlpattern: string, handler: HttpHandler): void;
search(urlpattern: string, handler: HttpHandler): void;
all(urlpattern: string, handler: HttpHandler): void;
redirect(urlpattern: string, to: string): void;
}
export interface Options {
paramsName?: string;
pageNotFound?: (req: ServerRequest, res: ServerResponse) => void;
errorHandler?: (err:Error, req: ServerRequest, res: ServerResponse) => void;
}
export function _UrlRouterfunc(handler: (app: App) => void, options?: any): void;
export interface HttpHandler {
(req: ServerRequest, res: ServerResponse, next?: () => void): void;
}
}
declare module "urlrouter" {
import _UrlRouterInternal = require("_UrlRouterInternal");
function _UrlRouterInternal(handler: (app: _UrlRouterInternal.App) => void): _UrlRouterInternal.HttpHandler;
export = _UrlRouterInternal;
}