1.0.6 • Published 3 years ago

worker-route-dispatcher v1.0.6

Weekly downloads
-
License
Apache-2.0
Repository
-
Last release
3 years ago

Route Dispatcher

The worker-route-dispatcher module dispatches worker requests to action handlers.

To use:

import {RouteDispatcher} from "worker-route-dispatcher";

const dispatcher = new RouteDispatcher();

dispatcher.notFound(notFoundHandler);
dispatcher.add("/post/:id*", getPostByIdAction);

const response = dispatcher.dispatch(request.url);
return response;

Where notFoundHandler is:

async function notFoundHandler(req, url) {
    return new Response("Not found.", { status: 404 });
}

And matched routes have a function signature as follows:

async function(params, req, url) { ... }

For example:

async function getPostByIdAction({id}, req, url) {
    const idPath = id.join("/");
    return new Response(JSON.stringify({}));
};
1.0.6

3 years ago

1.0.5

3 years ago

1.0.4

3 years ago

1.0.3

3 years ago

1.0.2

3 years ago

1.0.1

3 years ago

1.0.0

3 years ago