1.0.6 • Published 2 years ago

worker-route-dispatcher v1.0.6

Weekly downloads
-
License
Apache-2.0
Repository
-
Last release
2 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

2 years ago

1.0.5

2 years ago

1.0.4

2 years ago

1.0.3

2 years ago

1.0.2

2 years ago

1.0.1

2 years ago

1.0.0

2 years ago