njsbacker/components/Main.js
2022-10-05 09:27:14 +03:00

44 lines
895 B
JavaScript

const express = require('express');
const https = require('https');
const version = 'v 1.0.0';
class Main {
constructor (send_headers = true) {
this.send_headers = send_headers;
this.methods = new Object();
}
method (methodObj) {
this.methods[methodObj.path] = methodObj;
}
router (returnMiddlewareFunction = true, middlewareFunction = (req, res, next) => next()) {
let router = express.Router();
for (let path in this.methods) {
for (let methodId in this.methods[path].allowedMethods) {
router[this.methods[path].allowedMethods[methodId]](async (req, res) => {
// (!) Mainbody
});
}
}
if (returnMiddlewareFunction) {
return middlewareFunction, router;
}
else {
return router;
}
}
server (mountPath = '/', options = null) {
let app = express();
app.use(mountPath, this.router());
return app;
}
}
module.exports = Main;