miolo 0.7.3 → 0.7.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cli/miolo.cli.iife.bundle.js +1 -1
- package/dist/cli/miolo.cli.iife.bundle.min.js +1 -1
- package/dist/cli/miolo.cli.iife.js +1 -1
- package/dist/cli/miolo.cli.iife.min.js +1 -1
- package/dist/cli/miolo.cli.min.mjs +1 -1
- package/dist/cli/miolo.cli.mjs +1 -1
- package/dist/cli/miolo.cli.umd.bundle.js +1 -1
- package/dist/cli/miolo.cli.umd.bundle.min.js +1 -1
- package/dist/cli/miolo.cli.umd.js +1 -1
- package/dist/cli/miolo.cli.umd.min.js +1 -1
- package/dist/cli-react/miolo.cli-react.iife.bundle.js +1 -1
- package/dist/cli-react/miolo.cli-react.iife.bundle.min.js +1 -1
- package/dist/cli-react/miolo.cli-react.iife.js +1 -1
- package/dist/cli-react/miolo.cli-react.iife.min.js +1 -1
- package/dist/cli-react/miolo.cli-react.min.mjs +1 -1
- package/dist/cli-react/miolo.cli-react.mjs +1 -1
- package/dist/cli-react/miolo.cli-react.umd.bundle.js +1 -1
- package/dist/cli-react/miolo.cli-react.umd.bundle.min.js +1 -1
- package/dist/cli-react/miolo.cli-react.umd.js +1 -1
- package/dist/cli-react/miolo.cli-react.umd.min.js +1 -1
- package/dist/server/miolo.server.cjs +9 -6
- package/dist/server/miolo.server.min.mjs +2 -2
- package/dist/server/miolo.server.mjs +5 -2
- package/dist/server/miolo.server.mjs.map +1 -1
- package/dist/server/miolo.server.node.mjs +9 -6
- package/package.json +1 -1
package/dist/cli/miolo.cli.mjs
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* miolo v0.7.
|
|
2
|
+
* miolo v0.7.4
|
|
3
3
|
*
|
|
4
4
|
* Copyright (c) Donato Lorenzo <donato@afialapis.com>
|
|
5
5
|
*
|
|
@@ -1071,7 +1071,7 @@ function init_request_middleware(app) {
|
|
|
1071
1071
|
function _request_middleware() {
|
|
1072
1072
|
_request_middleware = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee(ctx, next) {
|
|
1073
1073
|
var _ctx$session;
|
|
1074
|
-
var logger, ip, started, sreq, sbody, user, uid_desc, status, ststr, stcolor, stdesc, elapsed, tcolor, ssession;
|
|
1074
|
+
var logger, ip, started, clurl, sreq, sbody, user, uid_desc, status, ststr, stcolor, stdesc, elapsed, tcolor, ssession, rbody;
|
|
1075
1075
|
return _regeneratorRuntime().wrap(function _callee$(_context) {
|
|
1076
1076
|
while (1) switch (_context.prev = _context.next) {
|
|
1077
1077
|
case 0:
|
|
@@ -1089,13 +1089,14 @@ function init_request_middleware(app) {
|
|
|
1089
1089
|
ctx.request.ip = ip;
|
|
1090
1090
|
|
|
1091
1091
|
// Log something
|
|
1092
|
-
|
|
1092
|
+
clurl = ctx.request.url.indexOf('?') >= 0 ? ctx.request.url.substr(0, ctx.request.url.indexOf('?')) : ctx.request.url;
|
|
1093
|
+
sreq = tinguir.magenta(ip) + " " + tinguir.cyan(ctx.request.method) + " " + tinguir.cyan(clurl) + " [" + tinguir.cyan_light(REQUEST_COUNTER[ip]) + "/" + tinguir.cyan_light(ctx.requestId) + "]";
|
|
1093
1094
|
sbody = ctx.request.body != undefined ? JSON.stringify(ctx.request.body) : '';
|
|
1094
1095
|
logger.info(sreq + " - START");
|
|
1095
1096
|
logger.debug(sreq + " - Body: " + sbody);
|
|
1096
|
-
_context.next =
|
|
1097
|
+
_context.next = 15;
|
|
1097
1098
|
return next();
|
|
1098
|
-
case
|
|
1099
|
+
case 15:
|
|
1099
1100
|
user = ctx == null ? void 0 : (_ctx$session = ctx.session) == null ? void 0 : _ctx$session.user;
|
|
1100
1101
|
uid_desc = '';
|
|
1101
1102
|
if (user != undefined) {
|
|
@@ -1122,8 +1123,10 @@ function init_request_middleware(app) {
|
|
|
1122
1123
|
tcolor = elapsed < 1.0 ? tinguir.green : elapsed < 2.0 ? tinguir.yellow : tinguir.red;
|
|
1123
1124
|
ssession = ctx.session != undefined ? JSON.stringify(ctx.session) : '';
|
|
1124
1125
|
logger.debug(sreq + " - Session: " + ssession);
|
|
1126
|
+
rbody = ctx.body != undefined ? JSON.stringify(ctx.body) : '';
|
|
1127
|
+
logger.debug(sreq + " - Response: " + rbody);
|
|
1125
1128
|
logger.info(sreq + " - DONE " + stdesc + uid_desc + " (time " + tcolor(elapsed) + ")");
|
|
1126
|
-
case
|
|
1129
|
+
case 29:
|
|
1127
1130
|
case "end":
|
|
1128
1131
|
return _context.stop();
|
|
1129
1132
|
}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* miolo v0.7.
|
|
2
|
+
* miolo v0.7.4
|
|
3
3
|
*
|
|
4
4
|
* Copyright (c) Donato Lorenzo <donato@afialapis.com>
|
|
5
5
|
*
|
|
@@ -8,4 +8,4 @@
|
|
|
8
8
|
*
|
|
9
9
|
* @license MIT
|
|
10
10
|
*/
|
|
11
|
-
import e from"node:http";import r from"koa";import{createHttpTerminator as t}from"http-terminator";import o from"deepmerge";import n from"node:path";import{fileURLToPath as i}from"node:url";import{getConnection as a}from"calustra";export{getConnection}from"calustra";import l from"nodemailer";import{uncolor as u,gray as c,magenta as s,cyan as d,yellow as f,red_light as p,red as v,cyan_light as m,green as h,blue as y}from"tinguir";import g from"node:util";import b,{transports as x,createLogger as _,format as w}from"winston";import S from"koa-better-body";import k from"koa-convert";import O from"koa-compress";import{constants as E}from"node:zlib";import M from"koa-mount";import q from"koa-static";import R from"koa-favicon";import{performance as L}from"node:perf_hooks";import N from"@koa/router";import{readFileSync as j}from"node:fs";import A from"jwt-simple";import C from"koa-passport";import P from"passport-local";import U from"koa-session";import T from"koa-redis";import F from"@koa/cors";import J from"koa-proxies";import B from"koa-router";import z from"qs";import{renderToString as G}from"react-dom/server";import D from"node:os";import V from"diskspace";import{CronJob as H}from"cron";function I(e,r){var t=Object.keys(e);if(Object.getOwnPropertySymbols){var o=Object.getOwnPropertySymbols(e);r&&(o=o.filter((function(r){return Object.getOwnPropertyDescriptor(e,r).enumerable}))),t.push.apply(t,o)}return t}function W(e){for(var r=1;r<arguments.length;r++){var t=null!=arguments[r]?arguments[r]:{};r%2?I(Object(t),!0).forEach((function(r){Z(e,r,t[r])})):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(t)):I(Object(t)).forEach((function(r){Object.defineProperty(e,r,Object.getOwnPropertyDescriptor(t,r))}))}return e}function Y(e,r,t,o,n,i,a){try{var l=e[i](a),u=l.value}catch(c){return void t(c)}l.done?r(u):Promise.resolve(u).then(o,n)}function K(e){return function(){var r=this,t=arguments;return new Promise((function(o,n){var i=e.apply(r,t);function a(e){Y(i,o,n,a,l,"next",e)}function l(e){Y(i,o,n,a,l,"throw",e)}a(void 0)}))}}function Z(e,r,t){return(r=function(e){var r=function(e,r){if("object"!=typeof e||null===e)return e;var t=e[Symbol.toPrimitive];if(void 0!==t){var o=t.call(e,r||"default");if("object"!=typeof o)return o;throw new TypeError("@@toPrimitive must return a primitive value.")}return("string"===r?String:Number)(e)}(e,"string");return"symbol"==typeof r?r:String(r)}(r))in e?Object.defineProperty(e,r,{value:t,enumerable:!0,configurable:!0,writable:!0}):e[r]=t,e}var X=i(import.meta.url),Q=n.dirname(X),$={name:"miolo",http:{port:8001,hostname:"localhost",catcher_url:"/sys/jserror",static:{favicon:n.resolve(Q,"../static/img/miolo.ico"),folders:{}},cors:!1,proxy:!1},session:{salt:"SUPER_SALTY_YES?",secret:"SUPER_SECRET_KEY_KERE",options:{maxAge:864e5,secure:!0,sameSite:null}},db:{config:{dialect:"postgres",host:"localhost",port:5432,database:"miolo",user:"postgres",password:"postgres",max:5,min:0,idleTimeoutMillis:1e4},options:{log:"silly",tables:[]}},routes:{bodyField:void 0,crud:[{prefix:"",routes:[]}],queries:void 0},log:{level:"debug",format:{locale:"en-GB"},console:{enabled:!0,level:"silly"},file:{enabled:!0,level:"silly",filename:"/var/log/miolo.log"},mail:{enabled:!1,level:"warn",name:"miolo",from:"miolo@mail.com",to:"errors@mail.com"}},mail:{silent:!0,options:{port:25,host:"mail.com",authMethod:"PLAIN",secure:!1,tls:{rejectUnauthorized:!1},logger:!1,debug:!1},defaults:{name:"miolo",from:"miolo@mail.com",to:"errors@mail.com"}},auth:{},render:{},middlewares:[]};var{combine:ee,timestamp:re,_label:te,printf:oe,errors:ne}=w,ie=(e,r)=>{var t,o,n={silly:c,debug:s,verbose:d,info:f,warn:p,error:v},i={silly:"sly",debug:"dbg",verbose:"vbs",info:"inf",warn:"wrn",error:"err"},a=oe((r=>{var t,o=n[r.level],a=new Date(r.timestamp).toLocaleString((null==e||null===(t=e.format)||void 0===t?void 0:t.locale)||"en"),l="[miolo] ".concat(o(a)," ").concat(o(i[r.level])," ").concat(r.message);return r.stack?"".concat(l,"\n").concat(r.stack):l})),l=[];e.console.enabled&&l.push(new x.Console({humanReadableUnhandledException:!0,level:(null==e||null===(t=e.console)||void 0===t?void 0:t.level)||(null==e?void 0:e.level)||"silly",handleExceptions:!0}));e.file.enabled&&l.push(new x.File({filename:e.file.filename,level:(null==e||null===(o=e.file)||void 0===o?void 0:o.level)||(null==e?void 0:e.level)||"info",humanReadableUnhandledException:!0,handleExceptions:!0}));if(e.mail.enabled){var m=function(e,r){var t=function(t){b.Transport.call(this,t),t=t||{},this.level=e.level||"info",this.ename=(null==e?void 0:e.name)||r.defaults.name,this.to=e.to||r.defaults.to,this.from=e.from||r.defaults.from,this.humanReadableUnhandledException=t.humanReadableUnhandledException||!0,this.handleExceptions=t.handleExceptions||!0,this.json=t.json||!1,this.colorize=t.colorize||!1};return g.inherits(t,b.Transport),t.prototype.name="MailerLogger",t.prototype.log=function(t,o){var n=this,i="";try{i=t.message.split("\n")[0]}catch(c){i=t.message.toString()}i=u(i);var a=e.name+": ["+t.level.toUpperCase()+"] "+i,l={from:this.from,to:this.to,subject:a,text:u(t.message)};r.send(l,(function(){n.emit("logged"),o(null,!0)}))},t}(e.mail,r);x.MailerLogger=m,l.push(new x.MailerLogger({humanReadableUnhandledException:!0,handleExceptions:!0}))}return _({level:(null==e?void 0:e.level)||"silly",format:ee(ne({stack:!0}),re(),a),transports:l})},ae=(e,r)=>{var t=function(e,r){var t=arguments.length>2&&void 0!==arguments[2]&&arguments[2],o=l.createTransport(e,r);return{send:function(e,r){t?(console.info("*********************************"),console.info("This mail will not be send (emailing is disabled):"),console.info(e),console.info("*********************************")):(r||(r=function(e,r){e&&(console.error("NodeMailer error:"),console.error(e)),r&&(console.log("NodeMailer sent mail:"),console.log(r))}),o.sendMail(e,r))},verify:function(){console.info("[miolo][Verify][MAILER] Verifying..."),o.verify((function(e,r){e?(console.error("[miolo][Verify][MAILER] Verifying ERROR"),console.error(e)):console.info("[miolo][Verify][MAILER] Verifyed OK: Server is ready to take our messages")}))},options:e,defaults:r,silent:t}}(r.mail.options,r.mail.defaults),o=ie(r.log,t),n=W(W({},r.db.options),{},{log:o}),i={getConnection:()=>a(r.db.config,n),getModel:e=>a(r.db.config,n).getModel(e)},u={config:W({},r),emailer:t,logger:o,db:i};function c(){return(c=K((function*(e,r){e.miolo=u,yield r()}))).apply(this,arguments)}e.use((function(e,r){return c.apply(this,arguments)})),e.context.miolo=u},le=[401];var ue=i(import.meta.url),ce=n.dirname(ue),se=n.resolve(ce,"./miolo.ico"),de={total:0};var fe=i(import.meta.url),pe=n.dirname(fe),ve=j(n.resolve(pe,"./robots.txt"),"utf8");var me=(e,r,t)=>{var o=e.context.miolo.logger,n=()=>{try{var{make_guest_token:e}=r;if(null!=e)return e(t||{})}catch(n){}return function(e,r){var t=Math.random().toString(),o=null==e?void 0:e.secret;o||(o="miolo_unsafe_secret",r.error("Guest token made with an unsafe secret string. Please, configure your own through session.secret."));var n={admin:!1,buid:t};return A.encode(n,o)}(t||{},o)};function i(){return i=K((function*(e,r){var i=e.cookies.get("token")||e.headers.token;void 0!==i&&0!=i.length||(i=yield n(),o.debug("Guest token conceeded"));var a=function(e){var r,t=null==e||null===(r=e.options)||void 0===r?void 0:r.maxAge;isNaN(t)&&(t=86400);var o=new Date;return o.setSeconds(o.getSeconds()+t),{expires:o,httpOnly:!1}}(t);e.cookies.set("token",i,a),e.session={user:{name:"guest"},authenticated:!0,token:i},yield r()})),i.apply(this,arguments)}e.use((function(e,r){return i.apply(this,arguments)}))},he=(e,r)=>{var{auth_user:t,realm:o,paths:n}=r;function i(e,r){return a.apply(this,arguments)}function a(){return(a=K((function*(r,n){var i;try{i=(e=>{var r,t=null==e||null===(r=e.headers)||void 0===r?void 0:r.authorization;if(t)try{t=t.replace("Basic ","");try{t=Buffer.from(t,"base64").toString()}catch(i){t=atob(t)}var[o,n]=t.split(":");return{username:o,password:n}}catch(i){return}})(r.request)}catch(u){}var a=()=>{r.session={user:void 0,authenticated:!1},r.body={user:void 0,authenticated:!1},r.response.status=401,r.response.headers["WWW-Authenticate"]='Basic realm="'+o.replace(/"/g,'\\"')+'"'};if(!i)return a();var l=yield t(i.username,i.password,e.context.miolo);if(!1===l||null==l)return a();r.session={user:l,authenticated:!0},yield n()}))).apply(this,arguments)}o||(o="Secure Area"),null==n||0==n.length?e.use(i):n.map((r=>e.use(M(r,i))))},ye=new T;var ge=(e,r,t)=>r(null,e.id),be=(e,r,t)=>{r(Error("You need to define auth.passport.find_user_by_id"),null)},xe=(e,r,t,o)=>{t(Error("You need to define auth.passport.local_auth_user"),null)},_e=(e,r,t)=>{var{get_user_id:o,find_user_by_id:n,local_auth_user:i,url_login:a,url_logout:l,url_login_redirect:u,url_logout_redirect:c}=r,s=o||ge,d=n||be,f=i||xe,p=a||"/login",v=l||"/logout",m=new P.Strategy(((r,t,o)=>{f(r,t,o,e.context.miolo)}));!function(e,r){e.keys=[r.secret||"*secret*"];var t=W({store:ye},r.options||{});e.use(U(t,e))}(e,t),C.serializeUser(((r,t)=>{process.nextTick((function(){s(r,t,e.context.miolo)}))})),C.deserializeUser(((r,t)=>{process.nextTick((function(){d(r,t,e.context.miolo)}))})),C.use(m),e.use(C.initialize()),e.use(C.session());var h=function(){var e=K((function*(e,r){e.session.authenticated?(e.session.user=void 0,e.session.authenticated=!1,e.logout(),e.body={user:void 0,authenticated:!1},null!=c&&e.redirect(c)):(e.body={user:void 0,authenticated:!1},e.response.status=401)}));return function(r,t){return e.apply(this,arguments)}}(),y=new N;y.post(p,((e,r)=>C.authenticate("local",function(){var r=K((function*(r,t,o,n){if(!1!==t)return e.session.user=t,e.session.authenticated=!0,e.body={user:t,authenticated:!0},null!=u&&e.redirect(u),yield e.login(t);e.session.user=void 0,e.session.authenticated=!1,e.body={user:void 0,authenticated:!1,info:o,error:r},e.response.status=401}));return function(e,t,o,n){return r.apply(this,arguments)}}())(e))),y.get(v,h),y.post(v,h),e.use(y.routes())},we=(e,r)=>{null!=r&&0!=r.length&&r.map((r=>{function t(){return(t=K((function*(e,t){yield r(e),yield t()}))).apply(this,arguments)}e.use((function(e,r){return t.apply(this,arguments)}))}))},Se=(e,r,t)=>{try{var o=e[r];if(null!=o&&0!=o)return t(o)}catch(n){}},ke=(e,r)=>{var t=e.context.miolo.logger;Se(r,"cors",(r=>{if("simple"==r)t.debug("Setting CORS the simple way"),e.use(function(){var e=K((function*(e,r){e.set("Access-Control-Allow-Origin","*"),e.set("Access-Control-Expose-Headers","SourceMap,X-SourceMap"),yield r()}));return function(r,t){return e.apply(this,arguments)}}());else{var o=(e=>"object"==typeof e?e:{})(r);t.debug("Setting CORS headers for ".concat(JSON.stringify(o))),e.use(F(o))}})),Se(r,"proxy",(r=>{var[o,n]=(e=>{var r,t,o,n;return null==e&&(e={}),[(null===(r=e)||void 0===r?void 0:r.path)||"/",{target:(null===(t=e)||void 0===t?void 0:t.target)||"https://proxy.miolo.com",changeOrigin:null==(null===(o=e)||void 0===o?void 0:o.changeOrigin)||e.changeOrigin,logs:null==(null===(n=e)||void 0===n?void 0:n.logs)||e.logs}]})(r);t.debug("Setting Proxy for ".concat(o," to ").concat(n.target," ")),e.use(J(o,n))}))},Oe=function(){var e=K((function*(e){return!0}));return function(r){return e.apply(this,arguments)}}(),Ee=function(){var e=K((function*(e,r){return r}));return function(r,t){return e.apply(this,arguments)}}(),Me={require:!1,action:"redirect",redirect_url:"/",error_code:401},qe={use:!1,fieldNames:{created_by:"created_by",last_update_by:"last_update_by"}},Re=e=>{var r=(null==e?void 0:e.crud)||[];if(!r)return[];if(!Array.isArray(r))return[];var t=[];return r.map((r=>{var n=null==r?void 0:r.routes;if(n&&Array.isArray(n)){var i=(null==r?void 0:r.bodyField)||(null==e?void 0:e.bodyField),a=(null==r?void 0:r.before)||(null==e?void 0:e.before)||Oe,l=(null==r?void 0:r.after)||(null==e?void 0:e.after)||Ee,u=o(Me,(null==e?void 0:e.auth)||{},(null==r?void 0:r.auth)||{}),c=[];for(var s of n){var d="string"==typeof s?{name:s}:s;if(d.name){var f={name:d.name,url:(null==d?void 0:d.url)||d.name,mode:(null==d?void 0:d.mode)||"rw",bodyField:(null==d?void 0:d.bodyField)||i,useUserFields:o(qe,(null==d?void 0:d.useUserFields)||{}),auth:o(u,(null==d?void 0:d.auth)||{}),before:(null==d?void 0:d.before)||a,after:(null==d?void 0:d.after)||l};c.push(f)}}c.length>0&&t.push({prefix:(null==r?void 0:r.prefix)||"",routes:c})}})),t};function Le(e){var r=e.indexOf("?")>=0?e.substr(e.indexOf("?")+1):"";return r?z.parse(r):{}}function Ne(e,r,t,o){t.map((t=>{var n=t.prefix;t.routes.map((t=>{var i=e.getModel(t.name);if(i){for(var a=function(){var e=K((function*(e,r){var n,i=!0===(null==e||null===(n=e.session)||void 0===n?void 0:n.authenticated),a=t.auth;return!(!0===a.require||"read-only"===a.require&&"w"===r)||(i||("error"==a.action?(o.error("Unauthorized access. Throwing error ".concat(a.error_code)),e.throw(a.error_code,null,{})):"redirect"==a.action?(o.warn("Unauthorized access. Redirecting to ".concat(a.redirect_url)),e.redirect(a.redirect_url)):(o.error("Crud path ".concat(t.url," specified auth but no action")),e.body={})),i)}));return function(r,t){return e.apply(this,arguments)}}(),l=function(){var e=K((function*(e,r,o){var n,i;if(yield a(e,r)){var l=!0;if(null!=t&&t.before&&(l=yield t.before(e)),l){var u=null==e||null===(n=e.session)||void 0===n||null===(i=n.user)||void 0===i?void 0:i.id,c={};!0===t.useUserFields.use&&(c=t.useUserFields.fieldNames);var s,d={uid:u,fieldNames:c},f=yield o(d);null!=t&&t.after&&(f=yield t.after(e,f)),s=f,f=null==t.bodyField?s:{[t.bodyField]:s},e.body=f}else e.body={}}else e.body={}}));return function(r,t,o){return e.apply(this,arguments)}}(),u=function(){var e=K((function*(e){yield l(e,"r",function(){var r=K((function*(r){var t=Le(e.request.url),o={transaction:void 0};return yield i.read(t,o)}));return function(e){return r.apply(this,arguments)}}())}));return function(r){return e.apply(this,arguments)}}(),c=function(){var e=K((function*(e){yield l(e,"r",function(){var r=K((function*(r){var t=Le(e.request.url),o={transaction:void 0};return yield i.keyList(t,o)}));return function(e){return r.apply(this,arguments)}}())}));return function(r){return e.apply(this,arguments)}}(),s=function(){var e=K((function*(e){yield l(e,"r",function(){var r=K((function*(r){var t=Le(e.request.url),o={transaction:void 0};return yield i.find(t.id,o)}));return function(e){return r.apply(this,arguments)}}())}));return function(r){return e.apply(this,arguments)}}(),d=function(){var e=K((function*(e){yield l(e,"r",function(){var r=K((function*(r){var t=Le(e.request.url),o={transaction:void 0};return yield i.distinct(t.distinct_field,t,o)}));return function(e){return r.apply(this,arguments)}}())}));return function(r){return e.apply(this,arguments)}}(),f=function(){var e=K((function*(e){yield l(e,"w",function(){var r=K((function*(r){var t,o=e.request.fields;null!=r&&null!==(t=r.fieldNames)&&void 0!==t&&t.created_by&&(o[r.fieldNames.created_by]=r.uid);var n={transaction:void 0};return yield i.insert(o,n)}));return function(e){return r.apply(this,arguments)}}())}));return function(r){return e.apply(this,arguments)}}(),p=function(){var e=K((function*(e){yield l(e,"w",function(){var r=K((function*(r){var t,o=e.request.fields;null!=r&&null!==(t=r.fieldNames)&&void 0!==t&&t.last_update_by&&(o[r.fieldNames.last_update_by]=r.uid);var n={transaction:void 0};return yield i.update(o,{id:o.id},n)}));return function(e){return r.apply(this,arguments)}}())}));return function(r){return e.apply(this,arguments)}}(),v=function(){var e=K((function*(e){yield l(e,"w",function(){var r=K((function*(r){var t=e.request.fields,o={transaction:void 0};return yield i.delete({id:t.id},o)}));return function(e){return r.apply(this,arguments)}}())}));return function(r){return e.apply(this,arguments)}}(),m=n?"/".concat(n,"/").concat(t.url):"/".concat(t.url);m.indexOf("//")>=0;)m=m.replace(/\/\//g,"/");o.info("[miolo-router] Routing table ".concat(t.name," to ").concat(m));var h=t.mode.indexOf("r")>=0,y=t.mode.indexOf("w")>=0,g=t.mode.indexOf("u")>=0||y;h&&(r.get("".concat(m,"/find"),(e=>s(e))),r.get("".concat(m,"/read"),(e=>u(e))),r.get("".concat(m,"/distinct"),(e=>d(e))),r.get("".concat(m,"/key_list"),(e=>c(e)))),g&&(r.post("".concat(m,"/save"),(e=>f(e))),r.post("".concat(m,"/update"),(e=>p(e)))),y&&r.post("".concat(m,"/delete"),(e=>v(e)))}else o.error("[miolo-router] Could not get model for ".concat(t.name))}))}))}var je=e=>{var r=(null==e?void 0:e.queries)||[];if(!r)return[];if(!Array.isArray(r))return[];var t=[];return r.map((r=>{var n=null==r?void 0:r.routes;if(n&&Array.isArray(n)){var i=(null==r?void 0:r.before)||(null==e?void 0:e.before)||Oe,a=(null==r?void 0:r.after)||(null==e?void 0:e.after)||Ee,l=o(Me,(null==r?void 0:r.auth)||{},(null==e?void 0:e.auth)||{}),u=[];for(var c of n)if(c.url&&c.callback){var s={url:c.url,method:(null==c?void 0:c.method)||"GET",callback:c.callback,auth:o(l,(null==c?void 0:c.auth)||{}),before:(null==c?void 0:c.before)||i,after:(null==c?void 0:c.after)||a};u.push(s)}t.push({prefix:(null==r?void 0:r.prefix)||"",routes:u})}})),t};function Ae(e,r,t){var o=new B;try{var n=Re(t),i=je(t),a=n.length>0,l=i.length>0;if(!a&&!l)throw"[miolo-router] Could not get any route from the passed <routes> param";a&&Ne(r,o,n,r.log),l&&function(e,r,t){r.map((r=>{var o=r.prefix;r.routes.map((r=>{for(var n,i=o?"/".concat(o,"/").concat(r.url):"/".concat(r.url);i.indexOf("//")>=0;)i=i.replace(/\/\//g,"/");t.info("Routing ".concat((null===(n=r.callback)||void 0===n?void 0:n.name)||"callback"," to ").concat(r.method," ").concat(i));var a=function(){var e=K((function*(e){var o,n=!0===(null==e||null===(o=e.session)||void 0===o?void 0:o.authenticated),i=r.auth;return!(!0===i.require||"read-only"===i.require&&"POST"===r.method)||(n||("error"==i.action?(t.error("Unauthorized access. Throwing error ".concat(i.error_code)),e.throw(i.error_code,null,{})):"redirect"==i.action?(t.warn("Unauthorized access. Redirecting to ".concat(i.redirect_url)),e.redirect(i.redirect_url)):(t.error("Route path ".concat(r.url," specified auth but no action")),e.body={})),n)}));return function(r){return e.apply(this,arguments)}}(),l=function(){var e=K((function*(e){try{var o;if("GET"==r.method&&(null===(o=e.request)||void 0===o||!o.fields)&&e.request.url.indexOf("?")>0){var n=Le(e.request.url);n&&(e.request.fields=n)}}catch(u){t.error("Error while trying to qet query params for ".concat(e.request.url))}if(yield a(e)){var i=!0;if(null!=r&&r.before&&(i=yield r.before(e)),i){var l=yield r.callback(e);return null!=r&&r.after&&(l=yield r.after(e,l)),l}}}));return function(r){return e.apply(this,arguments)}}(),u=r.method.toLowerCase();e[u](i,(e=>l(e,r)))}))}))}(o,i,r.log)}catch(u){console.error(u),console.error("[miolo-router] Error initing the router. Probably config objects are not ok"),console.error("[miolo-router] connOrConfig:"),console.error(null==r?void 0:r.config),console.error("[miolo-router] routes:"),console.error(t)}e.use(o.routes())}var Ce=i(import.meta.url),Pe=n.dirname(Ce),Ue=j(n.resolve(Pe,"fallback_index.html"),"utf8");var Te=i(import.meta.url),Fe=n.dirname(Te),Je=j(n.resolve(Fe,"fallback_index.html"),"utf8");function Be(e){var r=function(e){function r(e){return e?e/1e6:0}function t(e){return e?e/1e6:0}return function(){var o=Math.round(r(D.freemem()),2),n=Math.round(r(D.totalmem()),2),i=Math.round(100*o/n,2);i>80?e.error("[SERVER][".concat(d("SysCheck"),"] RAM ").concat(f(o)," MB used of ").concat(h(n)," MB (").concat(f(i)," %)")):e.info("[SERVER][".concat(d("SysCheck"),"] RAM ").concat(f(o)," MB used of ").concat(h(n)," MB (").concat(f(i)," %)")),V.check("/",(function(r,o){var n=Math.round(t(o.used),2),i=Math.round(t(o.total),2),a=Math.round(t(o.free),2);a<1?e.error("[SERVER][".concat(d("SysCheck"),"] DISK ").concat(f(n)," GB used of ").concat(h(i)," GB (").concat(f(a)," GB free)")):e.info("[SERVER][".concat(d("SysCheck"),"] DISK ").concat(f(n)," GB used of ").concat(h(i)," GB (").concat(f(a)," GB free)"))}))}}(e);new H("30 * * * *",r,null,!0,"Europe/Madrid")}function ze(n,i){var a,l=new r,u=function(e){var r,t=o($,e);return t.auth_type=function(e){var r,t,o;return null!=e&&null!==(r=e.auth)&&void 0!==r&&r.basic?"basic":null!=e&&null!==(t=e.auth)&&void 0!==t&&t.passport?"passport":null!=e&&null!==(o=e.auth)&&void 0!==o&&o.custom?"custom":"guest"}(e),t.use_catcher=!(null==t||null===(r=t.http)||void 0===r||!r.catcher_url),t}(n);ae(l,u),(e=>{e.use(O({filter:function(e){return"application/json"==e||"text/html"==e},gzip:{flush:E.Z_SYNC_FLUSH},deflate:{flush:E.Z_SYNC_FLUSH},br:!1})),e.use(k(S({formLimit:"100mb",jsonLimit:"100mb",bufferLimit:"100mb"})))})(l),function(e){var r=e.context.miolo.logger;function t(){return(t=K((function*(e){if(e){var t=e.status||400;if(this.accepts(["text","json","html"])?"number"!=typeof t&&(t=500):(t=406,e.message="Unsupported type"),le.indexOf(t)>=0?r.warn("".concat(this.method," ").concat(this.url," - ").concat(t,": ").concat(e.message)):r.error(e),this.headerSent||!this.writable)return r.debug("headers were already sent, returning early"),void(e.headerSent=!0);this.type="json",this.status=t,this.body=JSON.stringify(this.body||"",null,2),this.length=Buffer.byteLength(this.body),this.res.end(this.body)}}))).apply(this,arguments)}e.context.onerror=function(e){return t.apply(this,arguments)}}(l),((e,r)=>{var{favicon:t,folders:o}=r;for(var[n,i]of(e.use(R(t||se)),Object.entries(o)))e.use(M(n,q(i,{index:!1})))})(l,null===(a=u.http)||void 0===a?void 0:a.static),function(e){function r(){return(r=K((function*(e,r){var t,o=e.miolo.logger,n=e.headers["x-real-ip"]||"127.0.0.1",i=L.now();e.request.body=W(W({},e.request.fields),e.request.files),de.total+=1,de[n]=(de[n]||0)+1,e.requestId=de.total,e.request.ip=n;var a="".concat(s(n)," ").concat(d(e.request.method)," ").concat(d(e.request.url)," [").concat(m(de[n]),"/").concat(m(e.requestId),"]"),l=null!=e.request.body?JSON.stringify(e.request.body):"";o.info("".concat(a," - START")),o.debug("".concat(a," - Body: ").concat(l)),yield r();var u=null==e||null===(t=e.session)||void 0===t?void 0:t.user,c="";null!=u&&(null!=u&&u.id?c=" - uid ".concat(null==u?void 0:u.id):null!=u&&u.token&&(c=" - token ".concat(null==u?void 0:u.token)));var p,y=e.response.status,g=y;200==y?p=h:y>200&&y<=299?(p=f,e.response.redirected&&e.response.url&&(g+=" -> ".concat(e.response.url))):p=v;var b="[".concat(p(g),"]"),x=parseFloat((L.now()-i)/1e3).toFixed(2),_=x<1?h:x<2?f:v,w=null!=e.session?JSON.stringify(e.session):"";o.debug("".concat(a," - Session: ").concat(w)),o.info("".concat(a," - DONE ").concat(b).concat(c," (time ").concat(_(x),")"))}))).apply(this,arguments)}e.use((function(e,t){return r.apply(this,arguments)}))}(l),function(e){function r(){return(r=K((function*(e){e.body=ve}))).apply(this,arguments)}var t=new N;t.get("/robots.txt",(function(e){return r.apply(this,arguments)})),e.use(t.routes())}(l),u.use_catcher&&function(e,r){function t(){return t=K((function*(e){var{error:r,warning:t,path:o,agent:n}=e.request.body,i=e.miolo.logger;if(t){var a="".concat(f("[JS Warning]")," on ").concat(y(o),": ").concat(t.msg,"\n")+"".concat(f("[JS Warning]")," File => ").concat(t.file,"\n")+"".concat(f("[JS Warning]")," Line => ").concat(t.line,"\n")+"".concat(f("[JS Warning]")," Col => ").concat(t.col,"\n")+"".concat(f("[JS Warning]")," Error => ").concat(JSON.stringify(t.error),"\n")+"".concat(f("[JS Warning]")," Agent => ").concat(n);i.warn(a)}else{var l="".concat(v("[JS Error]")," on ").concat(y(o),": ").concat(r.msg,"\n")+"".concat(v("[JS Error]")," File => ").concat(r.file,"\n")+"".concat(v("[JS Error]")," Line => ").concat(r.line,"\n")+"".concat(v("[JS Error]")," Col => ").concat(r.col,"\n")+"".concat(v("[JS Error]")," Error => ").concat(JSON.stringify(r.error),"\n")+"".concat(v("[JS Error]")," Agent => ").concat(n);i.error(l)}e.body={result:1}})),t.apply(this,arguments)}var o=new N;o.post(r,(function(e){return t.apply(this,arguments)})),e.use(o.routes())}(l,u.http.catcher_url),"guest"==u.auth_type&&me(l,u.auth.guest,null==u?void 0:u.session),"basic"==u.auth_type&&he(l,u.auth.basic),"passport"==u.auth_type&&_e(l,u.auth.passport,null==u?void 0:u.session),"custom"==u.auth_type&&((e,r)=>{var t=e.context.miolo.logger;try{var o=r(e);if("function"==typeof o)e.use(o);else if(Array.isArray(o)){var n=new N;o.map((e=>{var r=e.method.toLowerCase();n[r](e.url,e.callback)})),e.use(n.routes())}}catch(i){t.error("Custom auth error: ".concat(i,"'"))}})(l,u.auth.custom);var c=null==u?void 0:u.middlewares;if(c&&we(l,c),ke(l,u.http),null!=u&&u.routes){var p=l.context.miolo.db.getConnection();Ae(l,p,u.routes)}null!=(null==i?void 0:i.middleware)?l.use(i.middleware):null!=(null==i?void 0:i.ssr)?function(e,r,t,o){var n=(null==r?void 0:r.html)||Je;n.indexOf("{context}")<0&&e.context.miolo.logger.error("Provided HTML for rendering has no {context} template variable"),n.indexOf("{children}")<0&&e.context.miolo.logger.error("Provided HTML for rendering has no {children} template variable");var i=function(){var e=K((function*(e){var t={};try{t=yield r.ssr.loader(e)}catch(l){var o,n="URL: ".concat(e.request.url,"\nFields: ").concat(JSON.stringify((null===(o=e.request)||void 0===o?void 0:o.fields)||{})),i=null!=l&&l.stack?"".concat(l.toString(),"\n").concat(l.stack):l.toString(),a="".concat("Error produced by loader in render.ssr middleware","\n").concat(n,"\n").concat(i);e.miolo.logger.error(a)}return t}));return function(r){return e.apply(this,arguments)}}(),a=(e,r)=>{var t,o,n=!0===(null==e||null===(t=e.session)||void 0===t?void 0:t.authenticated);return{user:null==e||null===(o=e.session)||void 0===o?void 0:o.user,authenticated:n,ssr_data:r,extra:null==e?void 0:e.extra}},l=(e,i)=>{var a="",l={hostname:null==t?void 0:t.hostname,port:null==t?void 0:t.port,catcher_url:null==t?void 0:t.catcher_url,auth_type:o};try{a=G(r.ssr.renderer(e,i,l))}catch(u){e.miolo.logger.error("Missing renderer in render.ssr middleware"),e.miolo.logger.error(u),a="\n <div>\n MIOLO: Missing SSR renderer: ".concat(u.toString(),"\n </div> \n ")}return n.replace("{context}",JSON.stringify(i,null,2)).replace("{children}",a)};function u(){return(u=K((function*(e){var r=yield i(e),t=a(e,r),o=l(e,t);e.miolo.logger.debug("render_ssr_middleware() rendered HTML (".concat(Buffer.byteLength(o,"utf8")," bytes total) ")),e.body=o}))).apply(this,arguments)}e.use((function(e){return u.apply(this,arguments)}))}(l,i,u.http,u.auth_type):null!=i&&i.html?function(e,r){var t=(null==r?void 0:r.html)||Ue;t.indexOf("{context}")<0&&e.context.miolo.logger.error(v("Provided HTML for rendering has no {context} template variable")),t.indexOf("{children}")<0&&e.context.miolo.logger.error(v("Provided HTML for rendering has no {children} template variable"));var o=e=>{var r,t,o=!0===(null==e||null===(r=e.session)||void 0===r?void 0:r.authenticated);return{user:null==e||null===(t=e.session)||void 0===t?void 0:t.user,authenticated:o,ssr_data:void 0,extra:null==e?void 0:e.extra}},n=e=>t.replace("{context}",JSON.stringify(e,null,2));function i(){return(i=K((function*(e){var r=o(e),t=n(r);e.miolo.logger.debug("render_html_middleware() rendered HTML (".concat(Buffer.byteLength(t,"utf8")," bytes total) ")),e.body=t}))).apply(this,arguments)}var a=new N;a.get("/",(function(e){return i.apply(this,arguments)})),e.use(a.routes())}(l,i):function(e,r){function t(){return(t=K((function*(e){e.miolo.logger.debug("render_404_middleware() Not FOUND ".concat(e.url," ")),e.body={},e.response.status=404,e.response.body="Resource Not Found"}))).apply(this,arguments)}var o=new N;o.get("/",(function(e){return t.apply(this,arguments)})),e.use(o.routes())}(l);var g=function(){var r=K((function*(){var r=e.createServer(l.callback());yield((e,r,t)=>new Promise(((o,n)=>{e.listen(r,t,(e=>{e?n(e):o()}))})))(r,u.http.port,u.http.hostname),l.context.miolo.logger.info("miolo is listening on ".concat(u.http.hostname,":").concat(u.http.port)),l.server=r;var o=t({server:r});return l.stop_server=K((function*(){yield o.terminate(),l.context.miolo.logger.info("miolo has been shutdowned from ".concat(u.http.hostname,":").concat(u.http.port))})),Be(l.context.miolo.logger),l}));return function(){return r.apply(this,arguments)}}();return l.run=g,l}export{ze as miolo};
|
|
11
|
+
import e from"node:http";import r from"koa";import{createHttpTerminator as t}from"http-terminator";import o from"deepmerge";import n from"node:path";import{fileURLToPath as i}from"node:url";import{getConnection as a}from"calustra";export{getConnection}from"calustra";import l from"nodemailer";import{uncolor as u,gray as s,magenta as c,cyan as d,yellow as f,red_light as p,red as v,cyan_light as m,green as h,blue as y}from"tinguir";import g from"node:util";import b,{transports as x,createLogger as _,format as w}from"winston";import S from"koa-better-body";import O from"koa-convert";import k from"koa-compress";import{constants as E}from"node:zlib";import q from"koa-mount";import M from"koa-static";import R from"koa-favicon";import{performance as L}from"node:perf_hooks";import N from"@koa/router";import{readFileSync as j}from"node:fs";import A from"jwt-simple";import C from"koa-passport";import P from"passport-local";import U from"koa-session";import T from"koa-redis";import J from"@koa/cors";import F from"koa-proxies";import B from"koa-router";import z from"qs";import{renderToString as G}from"react-dom/server";import D from"node:os";import V from"diskspace";import{CronJob as H}from"cron";function I(e,r){var t=Object.keys(e);if(Object.getOwnPropertySymbols){var o=Object.getOwnPropertySymbols(e);r&&(o=o.filter((function(r){return Object.getOwnPropertyDescriptor(e,r).enumerable}))),t.push.apply(t,o)}return t}function W(e){for(var r=1;r<arguments.length;r++){var t=null!=arguments[r]?arguments[r]:{};r%2?I(Object(t),!0).forEach((function(r){Z(e,r,t[r])})):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(t)):I(Object(t)).forEach((function(r){Object.defineProperty(e,r,Object.getOwnPropertyDescriptor(t,r))}))}return e}function Y(e,r,t,o,n,i,a){try{var l=e[i](a),u=l.value}catch(s){return void t(s)}l.done?r(u):Promise.resolve(u).then(o,n)}function K(e){return function(){var r=this,t=arguments;return new Promise((function(o,n){var i=e.apply(r,t);function a(e){Y(i,o,n,a,l,"next",e)}function l(e){Y(i,o,n,a,l,"throw",e)}a(void 0)}))}}function Z(e,r,t){return(r=function(e){var r=function(e,r){if("object"!=typeof e||null===e)return e;var t=e[Symbol.toPrimitive];if(void 0!==t){var o=t.call(e,r||"default");if("object"!=typeof o)return o;throw new TypeError("@@toPrimitive must return a primitive value.")}return("string"===r?String:Number)(e)}(e,"string");return"symbol"==typeof r?r:String(r)}(r))in e?Object.defineProperty(e,r,{value:t,enumerable:!0,configurable:!0,writable:!0}):e[r]=t,e}var X=i(import.meta.url),Q=n.dirname(X),$={name:"miolo",http:{port:8001,hostname:"localhost",catcher_url:"/sys/jserror",static:{favicon:n.resolve(Q,"../static/img/miolo.ico"),folders:{}},cors:!1,proxy:!1},session:{salt:"SUPER_SALTY_YES?",secret:"SUPER_SECRET_KEY_KERE",options:{maxAge:864e5,secure:!0,sameSite:null}},db:{config:{dialect:"postgres",host:"localhost",port:5432,database:"miolo",user:"postgres",password:"postgres",max:5,min:0,idleTimeoutMillis:1e4},options:{log:"silly",tables:[]}},routes:{bodyField:void 0,crud:[{prefix:"",routes:[]}],queries:void 0},log:{level:"debug",format:{locale:"en-GB"},console:{enabled:!0,level:"silly"},file:{enabled:!0,level:"silly",filename:"/var/log/miolo.log"},mail:{enabled:!1,level:"warn",name:"miolo",from:"miolo@mail.com",to:"errors@mail.com"}},mail:{silent:!0,options:{port:25,host:"mail.com",authMethod:"PLAIN",secure:!1,tls:{rejectUnauthorized:!1},logger:!1,debug:!1},defaults:{name:"miolo",from:"miolo@mail.com",to:"errors@mail.com"}},auth:{},render:{},middlewares:[]};var{combine:ee,timestamp:re,_label:te,printf:oe,errors:ne}=w,ie=(e,r)=>{var t,o,n={silly:s,debug:c,verbose:d,info:f,warn:p,error:v},i={silly:"sly",debug:"dbg",verbose:"vbs",info:"inf",warn:"wrn",error:"err"},a=oe((r=>{var t,o=n[r.level],a=new Date(r.timestamp).toLocaleString((null==e||null===(t=e.format)||void 0===t?void 0:t.locale)||"en"),l="[miolo] ".concat(o(a)," ").concat(o(i[r.level])," ").concat(r.message);return r.stack?"".concat(l,"\n").concat(r.stack):l})),l=[];e.console.enabled&&l.push(new x.Console({humanReadableUnhandledException:!0,level:(null==e||null===(t=e.console)||void 0===t?void 0:t.level)||(null==e?void 0:e.level)||"silly",handleExceptions:!0}));e.file.enabled&&l.push(new x.File({filename:e.file.filename,level:(null==e||null===(o=e.file)||void 0===o?void 0:o.level)||(null==e?void 0:e.level)||"info",humanReadableUnhandledException:!0,handleExceptions:!0}));if(e.mail.enabled){var m=function(e,r){var t=function(t){b.Transport.call(this,t),t=t||{},this.level=e.level||"info",this.ename=(null==e?void 0:e.name)||r.defaults.name,this.to=e.to||r.defaults.to,this.from=e.from||r.defaults.from,this.humanReadableUnhandledException=t.humanReadableUnhandledException||!0,this.handleExceptions=t.handleExceptions||!0,this.json=t.json||!1,this.colorize=t.colorize||!1};return g.inherits(t,b.Transport),t.prototype.name="MailerLogger",t.prototype.log=function(t,o){var n=this,i="";try{i=t.message.split("\n")[0]}catch(s){i=t.message.toString()}i=u(i);var a=e.name+": ["+t.level.toUpperCase()+"] "+i,l={from:this.from,to:this.to,subject:a,text:u(t.message)};r.send(l,(function(){n.emit("logged"),o(null,!0)}))},t}(e.mail,r);x.MailerLogger=m,l.push(new x.MailerLogger({humanReadableUnhandledException:!0,handleExceptions:!0}))}return _({level:(null==e?void 0:e.level)||"silly",format:ee(ne({stack:!0}),re(),a),transports:l})},ae=(e,r)=>{var t=function(e,r){var t=arguments.length>2&&void 0!==arguments[2]&&arguments[2],o=l.createTransport(e,r);return{send:function(e,r){t?(console.info("*********************************"),console.info("This mail will not be send (emailing is disabled):"),console.info(e),console.info("*********************************")):(r||(r=function(e,r){e&&(console.error("NodeMailer error:"),console.error(e)),r&&(console.log("NodeMailer sent mail:"),console.log(r))}),o.sendMail(e,r))},verify:function(){console.info("[miolo][Verify][MAILER] Verifying..."),o.verify((function(e,r){e?(console.error("[miolo][Verify][MAILER] Verifying ERROR"),console.error(e)):console.info("[miolo][Verify][MAILER] Verifyed OK: Server is ready to take our messages")}))},options:e,defaults:r,silent:t}}(r.mail.options,r.mail.defaults),o=ie(r.log,t),n=W(W({},r.db.options),{},{log:o}),i={getConnection:()=>a(r.db.config,n),getModel:e=>a(r.db.config,n).getModel(e)},u={config:W({},r),emailer:t,logger:o,db:i};function s(){return(s=K((function*(e,r){e.miolo=u,yield r()}))).apply(this,arguments)}e.use((function(e,r){return s.apply(this,arguments)})),e.context.miolo=u},le=[401];var ue=i(import.meta.url),se=n.dirname(ue),ce=n.resolve(se,"./miolo.ico"),de={total:0};var fe=i(import.meta.url),pe=n.dirname(fe),ve=j(n.resolve(pe,"./robots.txt"),"utf8");var me=(e,r,t)=>{var o=e.context.miolo.logger,n=()=>{try{var{make_guest_token:e}=r;if(null!=e)return e(t||{})}catch(n){}return function(e,r){var t=Math.random().toString(),o=null==e?void 0:e.secret;o||(o="miolo_unsafe_secret",r.error("Guest token made with an unsafe secret string. Please, configure your own through session.secret."));var n={admin:!1,buid:t};return A.encode(n,o)}(t||{},o)};function i(){return i=K((function*(e,r){var i=e.cookies.get("token")||e.headers.token;void 0!==i&&0!=i.length||(i=yield n(),o.debug("Guest token conceeded"));var a=function(e){var r,t=null==e||null===(r=e.options)||void 0===r?void 0:r.maxAge;isNaN(t)&&(t=86400);var o=new Date;return o.setSeconds(o.getSeconds()+t),{expires:o,httpOnly:!1}}(t);e.cookies.set("token",i,a),e.session={user:{name:"guest"},authenticated:!0,token:i},yield r()})),i.apply(this,arguments)}e.use((function(e,r){return i.apply(this,arguments)}))},he=(e,r)=>{var{auth_user:t,realm:o,paths:n}=r;function i(e,r){return a.apply(this,arguments)}function a(){return(a=K((function*(r,n){var i;try{i=(e=>{var r,t=null==e||null===(r=e.headers)||void 0===r?void 0:r.authorization;if(t)try{t=t.replace("Basic ","");try{t=Buffer.from(t,"base64").toString()}catch(i){t=atob(t)}var[o,n]=t.split(":");return{username:o,password:n}}catch(i){return}})(r.request)}catch(u){}var a=()=>{r.session={user:void 0,authenticated:!1},r.body={user:void 0,authenticated:!1},r.response.status=401,r.response.headers["WWW-Authenticate"]='Basic realm="'+o.replace(/"/g,'\\"')+'"'};if(!i)return a();var l=yield t(i.username,i.password,e.context.miolo);if(!1===l||null==l)return a();r.session={user:l,authenticated:!0},yield n()}))).apply(this,arguments)}o||(o="Secure Area"),null==n||0==n.length?e.use(i):n.map((r=>e.use(q(r,i))))},ye=new T;var ge=(e,r,t)=>r(null,e.id),be=(e,r,t)=>{r(Error("You need to define auth.passport.find_user_by_id"),null)},xe=(e,r,t,o)=>{t(Error("You need to define auth.passport.local_auth_user"),null)},_e=(e,r,t)=>{var{get_user_id:o,find_user_by_id:n,local_auth_user:i,url_login:a,url_logout:l,url_login_redirect:u,url_logout_redirect:s}=r,c=o||ge,d=n||be,f=i||xe,p=a||"/login",v=l||"/logout",m=new P.Strategy(((r,t,o)=>{f(r,t,o,e.context.miolo)}));!function(e,r){e.keys=[r.secret||"*secret*"];var t=W({store:ye},r.options||{});e.use(U(t,e))}(e,t),C.serializeUser(((r,t)=>{process.nextTick((function(){c(r,t,e.context.miolo)}))})),C.deserializeUser(((r,t)=>{process.nextTick((function(){d(r,t,e.context.miolo)}))})),C.use(m),e.use(C.initialize()),e.use(C.session());var h=function(){var e=K((function*(e,r){e.session.authenticated?(e.session.user=void 0,e.session.authenticated=!1,e.logout(),e.body={user:void 0,authenticated:!1},null!=s&&e.redirect(s)):(e.body={user:void 0,authenticated:!1},e.response.status=401)}));return function(r,t){return e.apply(this,arguments)}}(),y=new N;y.post(p,((e,r)=>C.authenticate("local",function(){var r=K((function*(r,t,o,n){if(!1!==t)return e.session.user=t,e.session.authenticated=!0,e.body={user:t,authenticated:!0},null!=u&&e.redirect(u),yield e.login(t);e.session.user=void 0,e.session.authenticated=!1,e.body={user:void 0,authenticated:!1,info:o,error:r},e.response.status=401}));return function(e,t,o,n){return r.apply(this,arguments)}}())(e))),y.get(v,h),y.post(v,h),e.use(y.routes())},we=(e,r)=>{null!=r&&0!=r.length&&r.map((r=>{function t(){return(t=K((function*(e,t){yield r(e),yield t()}))).apply(this,arguments)}e.use((function(e,r){return t.apply(this,arguments)}))}))},Se=(e,r,t)=>{try{var o=e[r];if(null!=o&&0!=o)return t(o)}catch(n){}},Oe=(e,r)=>{var t=e.context.miolo.logger;Se(r,"cors",(r=>{if("simple"==r)t.debug("Setting CORS the simple way"),e.use(function(){var e=K((function*(e,r){e.set("Access-Control-Allow-Origin","*"),e.set("Access-Control-Expose-Headers","SourceMap,X-SourceMap"),yield r()}));return function(r,t){return e.apply(this,arguments)}}());else{var o=(e=>"object"==typeof e?e:{})(r);t.debug("Setting CORS headers for ".concat(JSON.stringify(o))),e.use(J(o))}})),Se(r,"proxy",(r=>{var[o,n]=(e=>{var r,t,o,n;return null==e&&(e={}),[(null===(r=e)||void 0===r?void 0:r.path)||"/",{target:(null===(t=e)||void 0===t?void 0:t.target)||"https://proxy.miolo.com",changeOrigin:null==(null===(o=e)||void 0===o?void 0:o.changeOrigin)||e.changeOrigin,logs:null==(null===(n=e)||void 0===n?void 0:n.logs)||e.logs}]})(r);t.debug("Setting Proxy for ".concat(o," to ").concat(n.target," ")),e.use(F(o,n))}))},ke=function(){var e=K((function*(e){return!0}));return function(r){return e.apply(this,arguments)}}(),Ee=function(){var e=K((function*(e,r){return r}));return function(r,t){return e.apply(this,arguments)}}(),qe={require:!1,action:"redirect",redirect_url:"/",error_code:401},Me={use:!1,fieldNames:{created_by:"created_by",last_update_by:"last_update_by"}},Re=e=>{var r=(null==e?void 0:e.crud)||[];if(!r)return[];if(!Array.isArray(r))return[];var t=[];return r.map((r=>{var n=null==r?void 0:r.routes;if(n&&Array.isArray(n)){var i=(null==r?void 0:r.bodyField)||(null==e?void 0:e.bodyField),a=(null==r?void 0:r.before)||(null==e?void 0:e.before)||ke,l=(null==r?void 0:r.after)||(null==e?void 0:e.after)||Ee,u=o(qe,(null==e?void 0:e.auth)||{},(null==r?void 0:r.auth)||{}),s=[];for(var c of n){var d="string"==typeof c?{name:c}:c;if(d.name){var f={name:d.name,url:(null==d?void 0:d.url)||d.name,mode:(null==d?void 0:d.mode)||"rw",bodyField:(null==d?void 0:d.bodyField)||i,useUserFields:o(Me,(null==d?void 0:d.useUserFields)||{}),auth:o(u,(null==d?void 0:d.auth)||{}),before:(null==d?void 0:d.before)||a,after:(null==d?void 0:d.after)||l};s.push(f)}}s.length>0&&t.push({prefix:(null==r?void 0:r.prefix)||"",routes:s})}})),t};function Le(e){var r=e.indexOf("?")>=0?e.substr(e.indexOf("?")+1):"";return r?z.parse(r):{}}function Ne(e,r,t,o){t.map((t=>{var n=t.prefix;t.routes.map((t=>{var i=e.getModel(t.name);if(i){for(var a=function(){var e=K((function*(e,r){var n,i=!0===(null==e||null===(n=e.session)||void 0===n?void 0:n.authenticated),a=t.auth;return!(!0===a.require||"read-only"===a.require&&"w"===r)||(i||("error"==a.action?(o.error("Unauthorized access. Throwing error ".concat(a.error_code)),e.throw(a.error_code,null,{})):"redirect"==a.action?(o.warn("Unauthorized access. Redirecting to ".concat(a.redirect_url)),e.redirect(a.redirect_url)):(o.error("Crud path ".concat(t.url," specified auth but no action")),e.body={})),i)}));return function(r,t){return e.apply(this,arguments)}}(),l=function(){var e=K((function*(e,r,o){var n,i;if(yield a(e,r)){var l=!0;if(null!=t&&t.before&&(l=yield t.before(e)),l){var u=null==e||null===(n=e.session)||void 0===n||null===(i=n.user)||void 0===i?void 0:i.id,s={};!0===t.useUserFields.use&&(s=t.useUserFields.fieldNames);var c,d={uid:u,fieldNames:s},f=yield o(d);null!=t&&t.after&&(f=yield t.after(e,f)),c=f,f=null==t.bodyField?c:{[t.bodyField]:c},e.body=f}else e.body={}}else e.body={}}));return function(r,t,o){return e.apply(this,arguments)}}(),u=function(){var e=K((function*(e){yield l(e,"r",function(){var r=K((function*(r){var t=Le(e.request.url),o={transaction:void 0};return yield i.read(t,o)}));return function(e){return r.apply(this,arguments)}}())}));return function(r){return e.apply(this,arguments)}}(),s=function(){var e=K((function*(e){yield l(e,"r",function(){var r=K((function*(r){var t=Le(e.request.url),o={transaction:void 0};return yield i.keyList(t,o)}));return function(e){return r.apply(this,arguments)}}())}));return function(r){return e.apply(this,arguments)}}(),c=function(){var e=K((function*(e){yield l(e,"r",function(){var r=K((function*(r){var t=Le(e.request.url),o={transaction:void 0};return yield i.find(t.id,o)}));return function(e){return r.apply(this,arguments)}}())}));return function(r){return e.apply(this,arguments)}}(),d=function(){var e=K((function*(e){yield l(e,"r",function(){var r=K((function*(r){var t=Le(e.request.url),o={transaction:void 0};return yield i.distinct(t.distinct_field,t,o)}));return function(e){return r.apply(this,arguments)}}())}));return function(r){return e.apply(this,arguments)}}(),f=function(){var e=K((function*(e){yield l(e,"w",function(){var r=K((function*(r){var t,o=e.request.fields;null!=r&&null!==(t=r.fieldNames)&&void 0!==t&&t.created_by&&(o[r.fieldNames.created_by]=r.uid);var n={transaction:void 0};return yield i.insert(o,n)}));return function(e){return r.apply(this,arguments)}}())}));return function(r){return e.apply(this,arguments)}}(),p=function(){var e=K((function*(e){yield l(e,"w",function(){var r=K((function*(r){var t,o=e.request.fields;null!=r&&null!==(t=r.fieldNames)&&void 0!==t&&t.last_update_by&&(o[r.fieldNames.last_update_by]=r.uid);var n={transaction:void 0};return yield i.update(o,{id:o.id},n)}));return function(e){return r.apply(this,arguments)}}())}));return function(r){return e.apply(this,arguments)}}(),v=function(){var e=K((function*(e){yield l(e,"w",function(){var r=K((function*(r){var t=e.request.fields,o={transaction:void 0};return yield i.delete({id:t.id},o)}));return function(e){return r.apply(this,arguments)}}())}));return function(r){return e.apply(this,arguments)}}(),m=n?"/".concat(n,"/").concat(t.url):"/".concat(t.url);m.indexOf("//")>=0;)m=m.replace(/\/\//g,"/");o.info("[miolo-router] Routing table ".concat(t.name," to ").concat(m));var h=t.mode.indexOf("r")>=0,y=t.mode.indexOf("w")>=0,g=t.mode.indexOf("u")>=0||y;h&&(r.get("".concat(m,"/find"),(e=>c(e))),r.get("".concat(m,"/read"),(e=>u(e))),r.get("".concat(m,"/distinct"),(e=>d(e))),r.get("".concat(m,"/key_list"),(e=>s(e)))),g&&(r.post("".concat(m,"/save"),(e=>f(e))),r.post("".concat(m,"/update"),(e=>p(e)))),y&&r.post("".concat(m,"/delete"),(e=>v(e)))}else o.error("[miolo-router] Could not get model for ".concat(t.name))}))}))}var je=e=>{var r=(null==e?void 0:e.queries)||[];if(!r)return[];if(!Array.isArray(r))return[];var t=[];return r.map((r=>{var n=null==r?void 0:r.routes;if(n&&Array.isArray(n)){var i=(null==r?void 0:r.before)||(null==e?void 0:e.before)||ke,a=(null==r?void 0:r.after)||(null==e?void 0:e.after)||Ee,l=o(qe,(null==r?void 0:r.auth)||{},(null==e?void 0:e.auth)||{}),u=[];for(var s of n)if(s.url&&s.callback){var c={url:s.url,method:(null==s?void 0:s.method)||"GET",callback:s.callback,auth:o(l,(null==s?void 0:s.auth)||{}),before:(null==s?void 0:s.before)||i,after:(null==s?void 0:s.after)||a};u.push(c)}t.push({prefix:(null==r?void 0:r.prefix)||"",routes:u})}})),t};function Ae(e,r,t){var o=new B;try{var n=Re(t),i=je(t),a=n.length>0,l=i.length>0;if(!a&&!l)throw"[miolo-router] Could not get any route from the passed <routes> param";a&&Ne(r,o,n,r.log),l&&function(e,r,t){r.map((r=>{var o=r.prefix;r.routes.map((r=>{for(var n,i=o?"/".concat(o,"/").concat(r.url):"/".concat(r.url);i.indexOf("//")>=0;)i=i.replace(/\/\//g,"/");t.info("Routing ".concat((null===(n=r.callback)||void 0===n?void 0:n.name)||"callback"," to ").concat(r.method," ").concat(i));var a=function(){var e=K((function*(e){var o,n=!0===(null==e||null===(o=e.session)||void 0===o?void 0:o.authenticated),i=r.auth;return!(!0===i.require||"read-only"===i.require&&"POST"===r.method)||(n||("error"==i.action?(t.error("Unauthorized access. Throwing error ".concat(i.error_code)),e.throw(i.error_code,null,{})):"redirect"==i.action?(t.warn("Unauthorized access. Redirecting to ".concat(i.redirect_url)),e.redirect(i.redirect_url)):(t.error("Route path ".concat(r.url," specified auth but no action")),e.body={})),n)}));return function(r){return e.apply(this,arguments)}}(),l=function(){var e=K((function*(e){try{var o;if("GET"==r.method&&(null===(o=e.request)||void 0===o||!o.fields)&&e.request.url.indexOf("?")>0){var n=Le(e.request.url);n&&(e.request.fields=n)}}catch(u){t.error("Error while trying to qet query params for ".concat(e.request.url))}if(yield a(e)){var i=!0;if(null!=r&&r.before&&(i=yield r.before(e)),i){var l=yield r.callback(e);return null!=r&&r.after&&(l=yield r.after(e,l)),l}}}));return function(r){return e.apply(this,arguments)}}(),u=r.method.toLowerCase();e[u](i,(e=>l(e,r)))}))}))}(o,i,r.log)}catch(u){console.error(u),console.error("[miolo-router] Error initing the router. Probably config objects are not ok"),console.error("[miolo-router] connOrConfig:"),console.error(null==r?void 0:r.config),console.error("[miolo-router] routes:"),console.error(t)}e.use(o.routes())}var Ce=i(import.meta.url),Pe=n.dirname(Ce),Ue=j(n.resolve(Pe,"fallback_index.html"),"utf8");var Te=i(import.meta.url),Je=n.dirname(Te),Fe=j(n.resolve(Je,"fallback_index.html"),"utf8");function Be(e){var r=function(e){function r(e){return e?e/1e6:0}function t(e){return e?e/1e6:0}return function(){var o=Math.round(r(D.freemem()),2),n=Math.round(r(D.totalmem()),2),i=Math.round(100*o/n,2);i>80?e.error("[SERVER][".concat(d("SysCheck"),"] RAM ").concat(f(o)," MB used of ").concat(h(n)," MB (").concat(f(i)," %)")):e.info("[SERVER][".concat(d("SysCheck"),"] RAM ").concat(f(o)," MB used of ").concat(h(n)," MB (").concat(f(i)," %)")),V.check("/",(function(r,o){var n=Math.round(t(o.used),2),i=Math.round(t(o.total),2),a=Math.round(t(o.free),2);a<1?e.error("[SERVER][".concat(d("SysCheck"),"] DISK ").concat(f(n)," GB used of ").concat(h(i)," GB (").concat(f(a)," GB free)")):e.info("[SERVER][".concat(d("SysCheck"),"] DISK ").concat(f(n)," GB used of ").concat(h(i)," GB (").concat(f(a)," GB free)"))}))}}(e);new H("30 * * * *",r,null,!0,"Europe/Madrid")}function ze(n,i){var a,l=new r,u=function(e){var r,t=o($,e);return t.auth_type=function(e){var r,t,o;return null!=e&&null!==(r=e.auth)&&void 0!==r&&r.basic?"basic":null!=e&&null!==(t=e.auth)&&void 0!==t&&t.passport?"passport":null!=e&&null!==(o=e.auth)&&void 0!==o&&o.custom?"custom":"guest"}(e),t.use_catcher=!(null==t||null===(r=t.http)||void 0===r||!r.catcher_url),t}(n);ae(l,u),(e=>{e.use(k({filter:function(e){return"application/json"==e||"text/html"==e},gzip:{flush:E.Z_SYNC_FLUSH},deflate:{flush:E.Z_SYNC_FLUSH},br:!1})),e.use(O(S({formLimit:"100mb",jsonLimit:"100mb",bufferLimit:"100mb"})))})(l),function(e){var r=e.context.miolo.logger;function t(){return(t=K((function*(e){if(e){var t=e.status||400;if(this.accepts(["text","json","html"])?"number"!=typeof t&&(t=500):(t=406,e.message="Unsupported type"),le.indexOf(t)>=0?r.warn("".concat(this.method," ").concat(this.url," - ").concat(t,": ").concat(e.message)):r.error(e),this.headerSent||!this.writable)return r.debug("headers were already sent, returning early"),void(e.headerSent=!0);this.type="json",this.status=t,this.body=JSON.stringify(this.body||"",null,2),this.length=Buffer.byteLength(this.body),this.res.end(this.body)}}))).apply(this,arguments)}e.context.onerror=function(e){return t.apply(this,arguments)}}(l),((e,r)=>{var{favicon:t,folders:o}=r;for(var[n,i]of(e.use(R(t||ce)),Object.entries(o)))e.use(q(n,M(i,{index:!1})))})(l,null===(a=u.http)||void 0===a?void 0:a.static),function(e){function r(){return(r=K((function*(e,r){var t,o=e.miolo.logger,n=e.headers["x-real-ip"]||"127.0.0.1",i=L.now();e.request.body=W(W({},e.request.fields),e.request.files),de.total+=1,de[n]=(de[n]||0)+1,e.requestId=de.total,e.request.ip=n;var a=e.request.url.indexOf("?")>=0?e.request.url.substr(0,e.request.url.indexOf("?")):e.request.url,l="".concat(c(n)," ").concat(d(e.request.method)," ").concat(d(a)," [").concat(m(de[n]),"/").concat(m(e.requestId),"]"),u=null!=e.request.body?JSON.stringify(e.request.body):"";o.info("".concat(l," - START")),o.debug("".concat(l," - Body: ").concat(u)),yield r();var s=null==e||null===(t=e.session)||void 0===t?void 0:t.user,p="";null!=s&&(null!=s&&s.id?p=" - uid ".concat(null==s?void 0:s.id):null!=s&&s.token&&(p=" - token ".concat(null==s?void 0:s.token)));var y,g=e.response.status,b=g;200==g?y=h:g>200&&g<=299?(y=f,e.response.redirected&&e.response.url&&(b+=" -> ".concat(e.response.url))):y=v;var x="[".concat(y(b),"]"),_=parseFloat((L.now()-i)/1e3).toFixed(2),w=_<1?h:_<2?f:v,S=null!=e.session?JSON.stringify(e.session):"";o.debug("".concat(l," - Session: ").concat(S));var O=null!=e.body?JSON.stringify(e.body):"";o.debug("".concat(l," - Response: ").concat(O)),o.info("".concat(l," - DONE ").concat(x).concat(p," (time ").concat(w(_),")"))}))).apply(this,arguments)}e.use((function(e,t){return r.apply(this,arguments)}))}(l),function(e){function r(){return(r=K((function*(e){e.body=ve}))).apply(this,arguments)}var t=new N;t.get("/robots.txt",(function(e){return r.apply(this,arguments)})),e.use(t.routes())}(l),u.use_catcher&&function(e,r){function t(){return t=K((function*(e){var{error:r,warning:t,path:o,agent:n}=e.request.body,i=e.miolo.logger;if(t){var a="".concat(f("[JS Warning]")," on ").concat(y(o),": ").concat(t.msg,"\n")+"".concat(f("[JS Warning]")," File => ").concat(t.file,"\n")+"".concat(f("[JS Warning]")," Line => ").concat(t.line,"\n")+"".concat(f("[JS Warning]")," Col => ").concat(t.col,"\n")+"".concat(f("[JS Warning]")," Error => ").concat(JSON.stringify(t.error),"\n")+"".concat(f("[JS Warning]")," Agent => ").concat(n);i.warn(a)}else{var l="".concat(v("[JS Error]")," on ").concat(y(o),": ").concat(r.msg,"\n")+"".concat(v("[JS Error]")," File => ").concat(r.file,"\n")+"".concat(v("[JS Error]")," Line => ").concat(r.line,"\n")+"".concat(v("[JS Error]")," Col => ").concat(r.col,"\n")+"".concat(v("[JS Error]")," Error => ").concat(JSON.stringify(r.error),"\n")+"".concat(v("[JS Error]")," Agent => ").concat(n);i.error(l)}e.body={result:1}})),t.apply(this,arguments)}var o=new N;o.post(r,(function(e){return t.apply(this,arguments)})),e.use(o.routes())}(l,u.http.catcher_url),"guest"==u.auth_type&&me(l,u.auth.guest,null==u?void 0:u.session),"basic"==u.auth_type&&he(l,u.auth.basic),"passport"==u.auth_type&&_e(l,u.auth.passport,null==u?void 0:u.session),"custom"==u.auth_type&&((e,r)=>{var t=e.context.miolo.logger;try{var o=r(e);if("function"==typeof o)e.use(o);else if(Array.isArray(o)){var n=new N;o.map((e=>{var r=e.method.toLowerCase();n[r](e.url,e.callback)})),e.use(n.routes())}}catch(i){t.error("Custom auth error: ".concat(i,"'"))}})(l,u.auth.custom);var s=null==u?void 0:u.middlewares;if(s&&we(l,s),Oe(l,u.http),null!=u&&u.routes){var p=l.context.miolo.db.getConnection();Ae(l,p,u.routes)}null!=(null==i?void 0:i.middleware)?l.use(i.middleware):null!=(null==i?void 0:i.ssr)?function(e,r,t,o){var n=(null==r?void 0:r.html)||Fe;n.indexOf("{context}")<0&&e.context.miolo.logger.error("Provided HTML for rendering has no {context} template variable"),n.indexOf("{children}")<0&&e.context.miolo.logger.error("Provided HTML for rendering has no {children} template variable");var i=function(){var e=K((function*(e){var t={};try{t=yield r.ssr.loader(e)}catch(l){var o,n="URL: ".concat(e.request.url,"\nFields: ").concat(JSON.stringify((null===(o=e.request)||void 0===o?void 0:o.fields)||{})),i=null!=l&&l.stack?"".concat(l.toString(),"\n").concat(l.stack):l.toString(),a="".concat("Error produced by loader in render.ssr middleware","\n").concat(n,"\n").concat(i);e.miolo.logger.error(a)}return t}));return function(r){return e.apply(this,arguments)}}(),a=(e,r)=>{var t,o,n=!0===(null==e||null===(t=e.session)||void 0===t?void 0:t.authenticated);return{user:null==e||null===(o=e.session)||void 0===o?void 0:o.user,authenticated:n,ssr_data:r,extra:null==e?void 0:e.extra}},l=(e,i)=>{var a="",l={hostname:null==t?void 0:t.hostname,port:null==t?void 0:t.port,catcher_url:null==t?void 0:t.catcher_url,auth_type:o};try{a=G(r.ssr.renderer(e,i,l))}catch(u){e.miolo.logger.error("Missing renderer in render.ssr middleware"),e.miolo.logger.error(u),a="\n <div>\n MIOLO: Missing SSR renderer: ".concat(u.toString(),"\n </div> \n ")}return n.replace("{context}",JSON.stringify(i,null,2)).replace("{children}",a)};function u(){return(u=K((function*(e){var r=yield i(e),t=a(e,r),o=l(e,t);e.miolo.logger.debug("render_ssr_middleware() rendered HTML (".concat(Buffer.byteLength(o,"utf8")," bytes total) ")),e.body=o}))).apply(this,arguments)}e.use((function(e){return u.apply(this,arguments)}))}(l,i,u.http,u.auth_type):null!=i&&i.html?function(e,r){var t=(null==r?void 0:r.html)||Ue;t.indexOf("{context}")<0&&e.context.miolo.logger.error(v("Provided HTML for rendering has no {context} template variable")),t.indexOf("{children}")<0&&e.context.miolo.logger.error(v("Provided HTML for rendering has no {children} template variable"));var o=e=>{var r,t,o=!0===(null==e||null===(r=e.session)||void 0===r?void 0:r.authenticated);return{user:null==e||null===(t=e.session)||void 0===t?void 0:t.user,authenticated:o,ssr_data:void 0,extra:null==e?void 0:e.extra}},n=e=>t.replace("{context}",JSON.stringify(e,null,2));function i(){return(i=K((function*(e){var r=o(e),t=n(r);e.miolo.logger.debug("render_html_middleware() rendered HTML (".concat(Buffer.byteLength(t,"utf8")," bytes total) ")),e.body=t}))).apply(this,arguments)}var a=new N;a.get("/",(function(e){return i.apply(this,arguments)})),e.use(a.routes())}(l,i):function(e,r){function t(){return(t=K((function*(e){e.miolo.logger.debug("render_404_middleware() Not FOUND ".concat(e.url," ")),e.body={},e.response.status=404,e.response.body="Resource Not Found"}))).apply(this,arguments)}var o=new N;o.get("/",(function(e){return t.apply(this,arguments)})),e.use(o.routes())}(l);var g=function(){var r=K((function*(){var r=e.createServer(l.callback());yield((e,r,t)=>new Promise(((o,n)=>{e.listen(r,t,(e=>{e?n(e):o()}))})))(r,u.http.port,u.http.hostname),l.context.miolo.logger.info("miolo is listening on ".concat(u.http.hostname,":").concat(u.http.port)),l.server=r;var o=t({server:r});return l.stop_server=K((function*(){yield o.terminate(),l.context.miolo.logger.info("miolo has been shutdowned from ".concat(u.http.hostname,":").concat(u.http.port))})),Be(l.context.miolo.logger),l}));return function(){return r.apply(this,arguments)}}();return l.run=g,l}export{ze as miolo};
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* miolo v0.7.
|
|
2
|
+
* miolo v0.7.4
|
|
3
3
|
*
|
|
4
4
|
* Copyright (c) Donato Lorenzo <donato@afialapis.com>
|
|
5
5
|
*
|
|
@@ -764,7 +764,8 @@ function init_request_middleware(app) {
|
|
|
764
764
|
ctx.request.ip = ip;
|
|
765
765
|
|
|
766
766
|
// Log something
|
|
767
|
-
var
|
|
767
|
+
var clurl = ctx.request.url.indexOf('?') >= 0 ? ctx.request.url.substr(0, ctx.request.url.indexOf('?')) : ctx.request.url;
|
|
768
|
+
var sreq = "".concat(magenta(ip), " ").concat(cyan(ctx.request.method), " ").concat(cyan(clurl), " [").concat(cyan_light(REQUEST_COUNTER[ip]), "/").concat(cyan_light(ctx.requestId), "]");
|
|
768
769
|
var sbody = ctx.request.body != undefined ? JSON.stringify(ctx.request.body) : '';
|
|
769
770
|
logger.info("".concat(sreq, " - START"));
|
|
770
771
|
logger.debug("".concat(sreq, " - Body: ").concat(sbody));
|
|
@@ -796,6 +797,8 @@ function init_request_middleware(app) {
|
|
|
796
797
|
var tcolor = elapsed < 1.0 ? green : elapsed < 2.0 ? yellow : red;
|
|
797
798
|
var ssession = ctx.session != undefined ? JSON.stringify(ctx.session) : '';
|
|
798
799
|
logger.debug("".concat(sreq, " - Session: ").concat(ssession));
|
|
800
|
+
var rbody = ctx.body != undefined ? JSON.stringify(ctx.body) : '';
|
|
801
|
+
logger.debug("".concat(sreq, " - Response: ").concat(rbody));
|
|
799
802
|
logger.info("".concat(sreq, " - DONE ").concat(stdesc).concat(uid_desc, " (time ").concat(tcolor(elapsed), ")"));
|
|
800
803
|
});
|
|
801
804
|
return _request_middleware.apply(this, arguments);
|