release: 0.1.2

This commit is contained in:
2024-08-01 04:58:14 +08:00
parent c216c0a62f
commit 79b9fba1cd
6 changed files with 145 additions and 14 deletions

View File

@ -59,4 +59,25 @@ describe('Test server', () => {
expect(status).toEqual(200);
expect(data).toEqual('hit');
});
test('dynamic handler', async () => {
expect.assertions(6);
const { status: firstStatus, data: firstData } = await Instance.get(
`/handler`,
);
const { data, status } = await Instance.get(`/handler/add`);
const { status: secondStatus, data: secondData } = await Instance.get(
`/handler`,
);
expect(firstStatus).toEqual(200);
expect(firstData).toEqual('miss');
expect(status).toEqual(200);
expect(data).toEqual('added');
expect(secondStatus).toEqual(200);
expect(secondData).toEqual('hit');
});
});

View File

@ -7,6 +7,20 @@ App.binding(
App.create('GET', async () => '200 OK'),
);
const dynamicHandler = new handlersJS.handler('GET', [
async () => new handlersJS.response('miss'),
]);
App.binding('/handler', dynamicHandler);
App.binding(
'/handler/add',
App.create('GET', async () => {
dynamicHandler.add(async () => new handlersJS.response('hit'));
return 'added';
}),
);
App.binding(
'/post',
App.create(