|
@@ -46,15 +46,15 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
};
|
|
};
|
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
exports.Server = void 0;
|
|
exports.Server = void 0;
|
|
|
|
+const path_1 = __importDefault(require("path"));
|
|
|
|
+const fs_1 = __importDefault(require("fs"));
|
|
|
|
+const http_1 = __importDefault(require("http"));
|
|
const express_1 = __importDefault(require("express"));
|
|
const express_1 = __importDefault(require("express"));
|
|
-const http_1 = require("../base/http");
|
|
|
|
|
|
+const http_2 = require("../base/http");
|
|
const exceptions_1 = require("../base/exceptions");
|
|
const exceptions_1 = require("../base/exceptions");
|
|
const exceptions_2 = require("../base/exceptions");
|
|
const exceptions_2 = require("../base/exceptions");
|
|
const logger_1 = require("../base/logger");
|
|
const logger_1 = require("../base/logger");
|
|
const i18n_1 = require("../base/i18n");
|
|
const i18n_1 = require("../base/i18n");
|
|
-const path_1 = __importDefault(require("path"));
|
|
|
|
-const fs_1 = __importDefault(require("fs"));
|
|
|
|
-const http_2 = __importDefault(require("http"));
|
|
|
|
const ws_1 = require("ws");
|
|
const ws_1 = require("ws");
|
|
const exceptions_3 = require("../base/exceptions");
|
|
const exceptions_3 = require("../base/exceptions");
|
|
const exceptions_4 = require("../base/exceptions");
|
|
const exceptions_4 = require("../base/exceptions");
|
|
@@ -65,7 +65,7 @@ class Server {
|
|
constructor(properties) {
|
|
constructor(properties) {
|
|
var _a, _b, _c, _d, _e, _f, _g;
|
|
var _a, _b, _c, _d, _e, _f, _g;
|
|
this.instance = (0, express_1.default)();
|
|
this.instance = (0, express_1.default)();
|
|
- this.httpServer = http_2.default.createServer(this.instance);
|
|
|
|
|
|
+ this.httpServer = http_1.default.createServer(this.instance);
|
|
this.port = properties.port;
|
|
this.port = properties.port;
|
|
this.host = properties.host || `http://localhost:${this.port}`;
|
|
this.host = properties.host || `http://localhost:${this.port}`;
|
|
this.i18n = i18n_1.i18nLoader.getInstance();
|
|
this.i18n = i18n_1.i18nLoader.getInstance();
|
|
@@ -128,9 +128,9 @@ class Server {
|
|
handlers.push(this.httpHandlers[key]);
|
|
handlers.push(this.httpHandlers[key]);
|
|
handlers.sort((a, b) => a.getOrder() - b.getOrder());
|
|
handlers.sort((a, b) => a.getOrder() - b.getOrder());
|
|
for (const handler of handlers) {
|
|
for (const handler of handlers) {
|
|
- if (handler instanceof http_1.Middleware)
|
|
|
|
|
|
+ if (handler instanceof http_2.Middleware)
|
|
this.addMiddleware(handler);
|
|
this.addMiddleware(handler);
|
|
- else if (handler instanceof http_1.Route)
|
|
|
|
|
|
+ else if (handler instanceof http_2.Route)
|
|
this.addRoute(handler);
|
|
this.addRoute(handler);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
@@ -145,9 +145,9 @@ class Server {
|
|
if (route.getRoute() == null)
|
|
if (route.getRoute() == null)
|
|
throw new exceptions_1.RouteNotSetException();
|
|
throw new exceptions_1.RouteNotSetException();
|
|
switch (route.getMethod()) {
|
|
switch (route.getMethod()) {
|
|
- case http_1.HttpMethod.GET:
|
|
|
|
|
|
+ case http_2.HttpMethod.GET:
|
|
return this.get(route);
|
|
return this.get(route);
|
|
- case http_1.HttpMethod.POST:
|
|
|
|
|
|
+ case http_2.HttpMethod.POST:
|
|
return this.post(route);
|
|
return this.post(route);
|
|
default:
|
|
default:
|
|
throw new exceptions_2.IncorrectMethodException();
|
|
throw new exceptions_2.IncorrectMethodException();
|
|
@@ -158,11 +158,11 @@ class Server {
|
|
return this;
|
|
return this;
|
|
for (const routeName in this.httpHandlers) {
|
|
for (const routeName in this.httpHandlers) {
|
|
const route = this.httpHandlers[routeName];
|
|
const route = this.httpHandlers[routeName];
|
|
- if (!(route instanceof http_1.Route))
|
|
|
|
|
|
+ if (!(route instanceof http_2.Route))
|
|
continue;
|
|
continue;
|
|
if (route.getRoute() == null)
|
|
if (route.getRoute() == null)
|
|
throw new exceptions_1.RouteNotSetException();
|
|
throw new exceptions_1.RouteNotSetException();
|
|
- if (![http_1.HttpMethod.GET, http_1.HttpMethod.POST].includes(route.getMethod()))
|
|
|
|
|
|
+ if (![http_2.HttpMethod.GET, http_2.HttpMethod.POST].includes(route.getMethod()))
|
|
throw new exceptions_2.IncorrectMethodException();
|
|
throw new exceptions_2.IncorrectMethodException();
|
|
const docs = route.getDocumentation();
|
|
const docs = route.getDocumentation();
|
|
if (docs.length > 0) {
|
|
if (docs.length > 0) {
|
|
@@ -238,7 +238,7 @@ class Server {
|
|
for (const file of files) {
|
|
for (const file of files) {
|
|
if (/\.js$/.test(file)) {
|
|
if (/\.js$/.test(file)) {
|
|
const { default: RouteClass } = yield Promise.resolve(`${path_1.default.join(dir, file)}`).then(s => __importStar(require(s)));
|
|
const { default: RouteClass } = yield Promise.resolve(`${path_1.default.join(dir, file)}`).then(s => __importStar(require(s)));
|
|
- if (RouteClass.prototype instanceof http_1.Route) {
|
|
|
|
|
|
+ if (RouteClass.prototype instanceof http_2.Route) {
|
|
this.httpHandlers[RouteClass.name] = new RouteClass(this);
|
|
this.httpHandlers[RouteClass.name] = new RouteClass(this);
|
|
}
|
|
}
|
|
else
|
|
else
|
|
@@ -254,7 +254,7 @@ class Server {
|
|
for (const file of files) {
|
|
for (const file of files) {
|
|
if (/\.js$/.test(file)) {
|
|
if (/\.js$/.test(file)) {
|
|
const { default: MiddlewareClass } = yield Promise.resolve(`${path_1.default.join(dir, file)}`).then(s => __importStar(require(s)));
|
|
const { default: MiddlewareClass } = yield Promise.resolve(`${path_1.default.join(dir, file)}`).then(s => __importStar(require(s)));
|
|
- if (MiddlewareClass.prototype instanceof http_1.Middleware) {
|
|
|
|
|
|
+ if (MiddlewareClass.prototype instanceof http_2.Middleware) {
|
|
this.httpHandlers[MiddlewareClass.name] = new MiddlewareClass(this);
|
|
this.httpHandlers[MiddlewareClass.name] = new MiddlewareClass(this);
|
|
}
|
|
}
|
|
else
|
|
else
|