@glandjs/http
Version:
A protocol adapter for HTTP built on top of the Gland architecture solution.
118 lines (117 loc) • 3.47 kB
JavaScript
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.HttpCore = void 0;
const enum_1 = require("./enum");
class HttpCore {
constructor(_adapter, options) {
this._adapter = _adapter;
this.initializeEvents(options);
}
initializeEvents(options) {
this._adapter.events.emit('options', options);
}
get broker() {
return this._adapter.events;
}
get id() {
return this.broker.id;
}
get settings() {
return;
}
listen(port, args) {
this._adapter.listen(port, args?.host, args?.message);
}
use(...args) {
this._adapter.use(...args);
}
_registerRoute(method, path, action) {
this._adapter.registerRoute(method, path, action);
return this;
}
get(path, action) {
return this._registerRoute(enum_1.RequestMethod.GET, path, action);
}
post(path, action) {
return this._registerRoute(enum_1.RequestMethod.POST, path, action);
}
put(path, action) {
return this._registerRoute(enum_1.RequestMethod.PUT, path, action);
}
delete(path, action) {
return this._registerRoute(enum_1.RequestMethod.DELETE, path, action);
}
patch(path, action) {
return this._registerRoute(enum_1.RequestMethod.PATCH, path, action);
}
head(path, action) {
return this._registerRoute(enum_1.RequestMethod.HEAD, path, action);
}
options(path, action) {
return this._registerRoute(enum_1.RequestMethod.OPTIONS, path, action);
}
all(path, action) {
return this._registerRoute(enum_1.RequestMethod.ALL, path, action);
}
search(path, action) {
return this._registerRoute(enum_1.RequestMethod.SEARCH, path, action);
}
propfind(path, action) {
return this._registerRoute(enum_1.RequestMethod.PROPFIND, path, action);
}
proppatch(path, action) {
return this._registerRoute(enum_1.RequestMethod.PROPPATCH, path, action);
}
mkcol(path, action) {
return this._registerRoute(enum_1.RequestMethod.MKCOL, path, action);
}
copy(path, action) {
return this._registerRoute(enum_1.RequestMethod.COPY, path, action);
}
move(path, action) {
return this._registerRoute(enum_1.RequestMethod.MOVE, path, action);
}
lock(path, action) {
return this._registerRoute(enum_1.RequestMethod.LOCK, path, action);
}
unlock(path, action) {
return this._registerRoute(enum_1.RequestMethod.UNLOCK, path, action);
}
enableCors(options) {
this._adapter.enableCors(options);
}
setViewEngine(engine) {
this._adapter.setViewEngine(engine);
return this;
}
setBaseViewsDir(path) {
this._adapter.setBaseViewsDir(path);
return this;
}
useStaticAssets(path) {
this._adapter.useStaticAssets(path);
}
setGlobalPrefix(prefix) {
this._adapter.setGlobalPrefix(prefix);
}
handleError(error, message) {
this._adapter.handleError(error, message);
}
json(options) {
this._adapter.json(options);
return this;
}
urlencoded(options) {
this._adapter.urlencoded(options);
return this;
}
raw(options) {
this._adapter.raw(options);
return this;
}
text(options) {
this._adapter.text(options);
return this;
}
}
exports.HttpCore = HttpCore;