@quiltjs/quilt
Version:
Lightweight, type-safe handler and router abstraction for Node HTTP servers.
48 lines • 1.28 kB
JavaScript
/**
* Adapter that implements the ServerEngineAdapter interface using Express.
*
* This adapter assumes you have already registered any body-parser or
* JSON middleware you need on the Express app.
*/
export class ExpressEngineAdapter {
app;
constructor({ app }) {
this.app = app;
}
get(path, handler) {
this.app.get(path, async (req, res) => {
await handler(req, res);
});
}
post(path, handler) {
this.app.post(path, async (req, res) => {
await handler(req, res);
});
}
put(path, handler) {
this.app.put(path, async (req, res) => {
await handler(req, res);
});
}
patch(path, handler) {
this.app.patch(path, async (req, res) => {
await handler(req, res);
});
}
delete(path, handler) {
this.app.delete(path, async (req, res) => {
await handler(req, res);
});
}
options(path, handler) {
this.app.options(path, async (req, res) => {
await handler(req, res);
});
}
head(path, handler) {
this.app.head(path, async (req, res) => {
await handler(req, res);
});
}
}
//# sourceMappingURL=ExpressEngineAdapter.js.map