UNPKG

tachijs

Version:

Highly testable dead simple web server written in Typescript

68 lines 2.16 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); const httpMethodMetaMap = new Map(); function getHttpMethodMetaList(controller) { const metaList = httpMethodMetaMap.get(controller); if (metaList == null) return []; return metaList; } exports.getHttpMethodMetaList = getHttpMethodMetaList; function setHttpMethodMetaList(controller, meta) { httpMethodMetaMap.set(controller, meta); } exports.setHttpMethodMetaList = setHttpMethodMetaList; function httpMethod(method, path, middleware = {}) { if (Array.isArray(middleware)) { middleware = { before: middleware }; } return function httpMethodDecorator(target, propertyKey, descriptor) { const previousHttpMethodList = getHttpMethodMetaList(target.constructor); const newHttpMethodList = [ ...previousHttpMethodList, { method, path, propertyKey, middleware: middleware } ]; setHttpMethodMetaList(target.constructor, newHttpMethodList); }; } exports.httpMethod = httpMethod; function httpGet(path, middlewares) { return httpMethod('get', path, middlewares); } exports.httpGet = httpGet; function httpPost(path, middlewares) { return httpMethod('post', path, middlewares); } exports.httpPost = httpPost; function httpPut(path, middlewares) { return httpMethod('put', path, middlewares); } exports.httpPut = httpPut; function httpPatch(path, middlewares) { return httpMethod('patch', path, middlewares); } exports.httpPatch = httpPatch; function httpDelete(path, middlewares) { return httpMethod('delete', path, middlewares); } exports.httpDelete = httpDelete; function httpOptions(path, middlewares) { return httpMethod('options', path, middlewares); } exports.httpOptions = httpOptions; function httpHead(path, middlewares) { return httpMethod('head', path, middlewares); } exports.httpHead = httpHead; function httpAll(path, middlewares) { return httpMethod('all', path, middlewares); } exports.httpAll = httpAll; //# sourceMappingURL=httpMethod.js.map