mirror of
https://github.com/186526/handlers.js
synced 2024-10-13 00:29:43 +00:00
Implements most platform-independent features
This commit is contained in:
43
test/index.ts
Normal file
43
test/index.ts
Normal file
@ -0,0 +1,43 @@
|
||||
import * as handlerJS from "../";
|
||||
|
||||
interface requestType {
|
||||
hood: boolean;
|
||||
id: number;
|
||||
}
|
||||
|
||||
const App = new handlerJS.rootRouter<requestType, any>();
|
||||
|
||||
App.binding(
|
||||
"/",
|
||||
App.create(handlerJS.method["ANY"], async (request) => {
|
||||
Promise.resolve("Hello World!");
|
||||
throw handlerJS.ChainInterrupted;
|
||||
})
|
||||
);
|
||||
|
||||
App.binding(
|
||||
"/*",
|
||||
App.create(handlerJS.method["ANY"], async (request) => "Fuck World!")
|
||||
);
|
||||
|
||||
App.route("/v1")
|
||||
.add(
|
||||
new handlerJS.route(
|
||||
["/echo", "/echo/*"],
|
||||
new handlerJS.handler(handlerJS.method["GET"], [
|
||||
async (request, response) => {
|
||||
response = response ?? new handlerJS.response("");
|
||||
response?.headers.set("Hello", "World");
|
||||
response.body = "echo";
|
||||
return response;
|
||||
},
|
||||
])
|
||||
)
|
||||
)
|
||||
.binding(
|
||||
"/:a/echo",
|
||||
App.create(
|
||||
handlerJS.method["GET"],
|
||||
async (request) => `echo with ${request.params.a}`
|
||||
)
|
||||
);
|
Reference in New Issue
Block a user