miolo 0.2.2 → 0.3.0
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/README.md +34 -1
- package/dist/cli/miolo.cli.iife.bundle.js +374 -0
- package/dist/cli/miolo.cli.iife.bundle.js.map +1 -0
- package/dist/cli/miolo.cli.iife.bundle.min.js +22 -0
- package/dist/cli/miolo.cli.iife.js +76 -0
- package/dist/cli/miolo.cli.iife.js.map +1 -0
- package/dist/cli/miolo.cli.iife.min.js +11 -0
- package/dist/cli/miolo.cli.min.mjs +11 -0
- package/dist/cli/miolo.cli.mjs +69 -0
- package/dist/cli/miolo.cli.mjs.map +1 -0
- package/dist/cli/miolo.cli.umd.bundle.js +375 -0
- package/dist/cli/miolo.cli.umd.bundle.js.map +1 -0
- package/dist/cli/miolo.cli.umd.bundle.min.js +22 -0
- package/dist/cli/miolo.cli.umd.js +77 -0
- package/dist/cli/miolo.cli.umd.js.map +1 -0
- package/dist/cli/miolo.cli.umd.min.js +11 -0
- package/dist/cli-react/miolo.cli-react.iife.bundle.js +1690 -0
- package/dist/cli-react/miolo.cli-react.iife.bundle.js.map +1 -0
- package/dist/cli-react/miolo.cli-react.iife.bundle.min.js +62 -0
- package/dist/cli-react/miolo.cli-react.iife.js +531 -0
- package/dist/cli-react/miolo.cli-react.iife.js.map +1 -0
- package/dist/cli-react/miolo.cli-react.iife.min.js +11 -0
- package/dist/cli-react/miolo.cli-react.min.mjs +11 -0
- package/dist/cli-react/miolo.cli-react.mjs +187 -0
- package/dist/cli-react/miolo.cli-react.mjs.map +1 -0
- package/dist/cli-react/miolo.cli-react.umd.bundle.js +1691 -0
- package/dist/cli-react/miolo.cli-react.umd.bundle.js.map +1 -0
- package/dist/cli-react/miolo.cli-react.umd.bundle.min.js +62 -0
- package/dist/cli-react/miolo.cli-react.umd.js +532 -0
- package/dist/cli-react/miolo.cli-react.umd.js.map +1 -0
- package/dist/cli-react/miolo.cli-react.umd.min.js +11 -0
- package/dist/server/miolo.ico +0 -0
- package/dist/{miolo.cjs → server/miolo.server.cjs} +320 -208
- package/dist/server/miolo.server.min.mjs +11 -0
- package/dist/{miolo.mjs → server/miolo.server.mjs} +292 -159
- package/dist/server/miolo.server.mjs.map +1 -0
- package/dist/{miolo.node.mjs → server/miolo.server.node.mjs} +321 -208
- package/dist/static/img/miolo.ico +0 -0
- package/dist/static/robots.txt +2 -0
- package/logo/favicon/miolo.ico +0 -0
- package/logo/favicon/miolo.png +0 -0
- package/logo/favicon/miolo_apple.png +0 -0
- package/logo/miolo-logo-name_200.png +0 -0
- package/package.json +63 -20
- package/dist/miolo.min.mjs +0 -11
- package/dist/miolo.mjs.map +0 -1
- package/lib/cacher/index.cjs +0 -76
- package/lib/cacher/verify.cjs +0 -27
- package/lib/config/defaults.cjs +0 -287
- package/lib/config/index.cjs +0 -12
- package/lib/emailer/index.cjs +0 -56
- package/lib/emailer/verify.cjs +0 -11
- package/lib/index.cjs +0 -40
- package/lib/logger/index.cjs +0 -91
- package/lib/logger/logger_mail.cjs +0 -56
- package/lib/logger/verify.cjs +0 -22
- package/lib/server/engines/cron/index.cjs +0 -12
- package/lib/server/engines/cron/syscheck.cjs +0 -41
- package/lib/server/engines/socket/index.cjs +0 -40
- package/lib/server/index.cjs +0 -134
- package/lib/server/middleware/auth/basic.cjs +0 -53
- package/lib/server/middleware/auth/guest.cjs +0 -72
- package/lib/server/middleware/auth/passport.cjs +0 -123
- package/lib/server/middleware/body.cjs +0 -50
- package/lib/server/middleware/catcher/index.cjs +0 -58
- package/lib/server/middleware/context.cjs +0 -23
- package/lib/server/middleware/extra.cjs +0 -27
- package/lib/server/middleware/headers.cjs +0 -68
- package/lib/server/middleware/request.cjs +0 -68
- package/lib/server/middleware/session/index.cjs +0 -26
- package/lib/server/middleware/session/store.cjs +0 -10
- package/lib/server/middleware/static.cjs +0 -25
- package/lib/server/routes/catch_js_error.cjs +0 -35
- package/lib/server/routes/html_render.cjs +0 -37
- package/lib/server/routes/robots.cjs +0 -27
- /package/{lib/server/routes → dist/server}/fallback_index.html +0 -0
- /package/{lib/server/static → dist/server}/robots.txt +0 -0
- /package/{lib/server/static/img/favicon.ico → dist/static/img/afialapis.ico} +0 -0
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* miolo v0.
|
|
2
|
+
* miolo v0.3.0
|
|
3
3
|
*
|
|
4
4
|
* Copyright (c) Donato Lorenzo <donato@afialapis.com>
|
|
5
5
|
*
|
|
@@ -9,33 +9,36 @@
|
|
|
9
9
|
* @license MIT
|
|
10
10
|
*/
|
|
11
11
|
import Koa from 'koa';
|
|
12
|
+
import { initCalustraRouter } from 'calustra/router';
|
|
12
13
|
import merge from 'assign-deep';
|
|
13
|
-
import path
|
|
14
|
+
import path from 'node:path';
|
|
14
15
|
import { fileURLToPath } from 'node:url';
|
|
15
|
-
import nodemailer from 'nodemailer';
|
|
16
|
-
import { uncolor, gray, magenta, cyan, yellow, red_light, red, green, blue } from 'tinguir';
|
|
17
|
-
import util, { promisify } from 'node:util';
|
|
18
|
-
import winston, { format, transports, createLogger } from 'winston';
|
|
19
16
|
import os from 'node:os';
|
|
20
17
|
import diskspace from 'diskspace';
|
|
18
|
+
import { cyan, yellow, green, uncolor, gray, magenta, red_light, red, blue } from 'tinguir';
|
|
21
19
|
import { CronJob } from 'cron';
|
|
22
|
-
import {
|
|
23
|
-
export { getConnection } from 'calustra
|
|
20
|
+
import { getConnection } from 'calustra';
|
|
21
|
+
export { getConnection } from 'calustra';
|
|
22
|
+
import nodemailer from 'nodemailer';
|
|
23
|
+
import util from 'node:util';
|
|
24
|
+
import winston, { format, transports, createLogger } from 'winston';
|
|
24
25
|
import koa_cors from '@koa/cors';
|
|
25
26
|
import koa_proxy from 'koa-proxies';
|
|
26
27
|
import koa_body_parser from 'koa-better-body';
|
|
27
28
|
import koa_convert from 'koa-convert';
|
|
28
29
|
import koa_compress from 'koa-compress';
|
|
29
|
-
import {
|
|
30
|
+
import { constants } from 'node:zlib';
|
|
30
31
|
import koa_mount from 'koa-mount';
|
|
31
32
|
import koa_serve from 'koa-static';
|
|
32
33
|
import koa_favicon from 'koa-favicon';
|
|
33
34
|
import { performance } from 'node:perf_hooks';
|
|
34
35
|
import koa_session from 'koa-session';
|
|
35
36
|
import RedisStore from 'koa-redis';
|
|
36
|
-
import fs from 'node:fs';
|
|
37
37
|
import Router from '@koa/router';
|
|
38
|
-
import
|
|
38
|
+
import { readFileSync } from 'node:fs';
|
|
39
|
+
import React, { useState, useEffect } from 'react';
|
|
40
|
+
import { StaticRouter } from 'react-router-dom/server';
|
|
41
|
+
import { renderToString } from 'react-dom/server';
|
|
39
42
|
import jwt from 'jwt-simple';
|
|
40
43
|
import auth from 'basic-auth';
|
|
41
44
|
import passport$1 from 'koa-passport';
|
|
@@ -387,9 +390,9 @@ function _extends() {
|
|
|
387
390
|
return _extends.apply(this, arguments);
|
|
388
391
|
}
|
|
389
392
|
|
|
390
|
-
var __my_filename = fileURLToPath(require('url').pathToFileURL(__filename).toString());
|
|
391
|
-
var __my_dirname = path.dirname(__my_filename);
|
|
392
|
-
var favicon = path.resolve(__my_dirname, '../
|
|
393
|
+
var __my_filename$3 = fileURLToPath(require('url').pathToFileURL(__filename).toString());
|
|
394
|
+
var __my_dirname$3 = path.dirname(__my_filename$3);
|
|
395
|
+
var favicon = path.resolve(__my_dirname$3, '../static/img/miolo.ico');
|
|
393
396
|
var base_config = {
|
|
394
397
|
name: 'miolo',
|
|
395
398
|
http: {
|
|
@@ -446,27 +449,25 @@ var base_config = {
|
|
|
446
449
|
},
|
|
447
450
|
|
|
448
451
|
db: {
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
|
|
456
|
-
|
|
457
|
-
|
|
458
|
-
|
|
459
|
-
|
|
460
|
-
|
|
461
|
-
idleTimeoutMillis: 10000 // The maximum time, in milliseconds, that a connection can be idle before being released. Use with combination of evict for proper working, for more details read https://github.com/coopernurse/node-pool/issues/178#issuecomment-327110870,
|
|
462
|
-
},
|
|
463
|
-
|
|
464
|
-
options: {
|
|
465
|
-
log: 'silly' // will be updated on the fly with miolo logger
|
|
466
|
-
}
|
|
452
|
+
config: {
|
|
453
|
+
dialect: 'postgres',
|
|
454
|
+
host: 'localhost',
|
|
455
|
+
port: 5432,
|
|
456
|
+
database: 'miolo',
|
|
457
|
+
user: 'postgres',
|
|
458
|
+
password: 'postgres',
|
|
459
|
+
max: 5,
|
|
460
|
+
// Maximum number of connection in pool
|
|
461
|
+
min: 0,
|
|
462
|
+
// Minimum number of connection in pool
|
|
463
|
+
idleTimeoutMillis: 10000 // The maximum time, in milliseconds, that a connection can be idle before being released. Use with combination of evict for proper working, for more details read https://github.com/coopernurse/node-pool/issues/178#issuecomment-327110870,
|
|
467
464
|
},
|
|
468
465
|
|
|
469
|
-
|
|
466
|
+
options: {
|
|
467
|
+
log: 'silly',
|
|
468
|
+
// will be updated on the fly with miolo logger
|
|
469
|
+
tables: []
|
|
470
|
+
}
|
|
470
471
|
},
|
|
471
472
|
routes: {
|
|
472
473
|
bodyField: undefined,
|
|
@@ -512,12 +513,12 @@ var base_config = {
|
|
|
512
513
|
queries: undefined
|
|
513
514
|
},
|
|
514
515
|
catcher: '/sys/jserror',
|
|
515
|
-
cacher: {
|
|
516
|
-
|
|
517
|
-
|
|
518
|
-
|
|
519
|
-
|
|
520
|
-
},
|
|
516
|
+
//cacher: {
|
|
517
|
+
// redis: {
|
|
518
|
+
// host: '127.0.0.1',
|
|
519
|
+
// port: 6379
|
|
520
|
+
// },
|
|
521
|
+
//},
|
|
521
522
|
log: {
|
|
522
523
|
level: 'debug',
|
|
523
524
|
format: {
|
|
@@ -669,6 +670,43 @@ function init_config(config) {
|
|
|
669
670
|
return merge(base_config, config);
|
|
670
671
|
}
|
|
671
672
|
|
|
673
|
+
function init_sys_check_and_log(logger) {
|
|
674
|
+
function toMB(bytes) {
|
|
675
|
+
if (!bytes) return 0;
|
|
676
|
+
return bytes / 1000000;
|
|
677
|
+
}
|
|
678
|
+
function toGB(kbytes) {
|
|
679
|
+
if (!kbytes) return 0;
|
|
680
|
+
return kbytes / 1000000;
|
|
681
|
+
}
|
|
682
|
+
function sys_check_and_log() {
|
|
683
|
+
var used = Math.round(toMB(os.freemem()), 2);
|
|
684
|
+
var total = Math.round(toMB(os.totalmem()), 2);
|
|
685
|
+
var perc = Math.round(used * 100 / total, 2);
|
|
686
|
+
if (perc > 80) {
|
|
687
|
+
logger.error("[SERVER][" + cyan('SysCheck') + "] RAM " + yellow(used) + " MB used of " + green(total) + " MB (" + yellow(perc) + " %)");
|
|
688
|
+
} else {
|
|
689
|
+
logger.info("[SERVER][" + cyan('SysCheck') + "] RAM " + yellow(used) + " MB used of " + green(total) + " MB (" + yellow(perc) + " %)");
|
|
690
|
+
}
|
|
691
|
+
diskspace.check('/', function (err, result) {
|
|
692
|
+
var used = Math.round(toGB(result.used), 2);
|
|
693
|
+
var total = Math.round(toGB(result.total), 2);
|
|
694
|
+
var free = Math.round(toGB(result.free), 2);
|
|
695
|
+
if (free < 1) {
|
|
696
|
+
logger.error("[SERVER][" + cyan('SysCheck') + "] DISK " + yellow(used) + " GB used of " + green(total) + " GB (" + yellow(free) + " GB free)");
|
|
697
|
+
} else {
|
|
698
|
+
logger.info("[SERVER][" + cyan('SysCheck') + "] DISK " + yellow(used) + " GB used of " + green(total) + " GB (" + yellow(free) + " GB free)");
|
|
699
|
+
}
|
|
700
|
+
});
|
|
701
|
+
}
|
|
702
|
+
return sys_check_and_log;
|
|
703
|
+
}
|
|
704
|
+
|
|
705
|
+
function init_cron(logger) {
|
|
706
|
+
var sys_check_and_log = init_sys_check_and_log(logger);
|
|
707
|
+
new CronJob('30 * * * *', sys_check_and_log, null, true, 'Europe/Madrid');
|
|
708
|
+
}
|
|
709
|
+
|
|
672
710
|
function init_emailer(options, defaults, silent) {
|
|
673
711
|
if (silent === void 0) {
|
|
674
712
|
silent = false;
|
|
@@ -843,42 +881,52 @@ var init_logger = function init_logger(config, emailer) {
|
|
|
843
881
|
return logger;
|
|
844
882
|
};
|
|
845
883
|
|
|
846
|
-
function
|
|
847
|
-
|
|
848
|
-
|
|
849
|
-
|
|
850
|
-
|
|
851
|
-
|
|
852
|
-
|
|
853
|
-
|
|
884
|
+
var init_context_middleware = function init_context_middleware(app, config) {
|
|
885
|
+
var emailer = init_emailer(config.mail.options, config.mail.defaults);
|
|
886
|
+
var logger = init_logger(config.log, emailer);
|
|
887
|
+
config.db.options.log = logger;
|
|
888
|
+
var getConnectionWrap = function getConnectionWrap() {
|
|
889
|
+
return getConnection(config.db.config, config.db.options);
|
|
890
|
+
};
|
|
891
|
+
var getModelWrap = function getModelWrap(name) {
|
|
892
|
+
var conn = getConnection(config.db.config, config.db.options);
|
|
893
|
+
return conn.getModel(name);
|
|
894
|
+
};
|
|
895
|
+
var db = {
|
|
896
|
+
getConnection: getConnectionWrap,
|
|
897
|
+
getModel: getModelWrap
|
|
898
|
+
};
|
|
899
|
+
|
|
900
|
+
// Assign miolo stuff to ctx
|
|
901
|
+
var mioloContext = {
|
|
902
|
+
config: _extends({}, config),
|
|
903
|
+
emailer: emailer,
|
|
904
|
+
logger: logger,
|
|
905
|
+
db: db
|
|
906
|
+
};
|
|
907
|
+
function context_middleware(_x, _x2) {
|
|
908
|
+
return _context_middleware.apply(this, arguments);
|
|
854
909
|
}
|
|
855
|
-
function
|
|
856
|
-
|
|
857
|
-
|
|
858
|
-
|
|
859
|
-
|
|
860
|
-
|
|
861
|
-
|
|
862
|
-
|
|
863
|
-
|
|
864
|
-
|
|
865
|
-
|
|
866
|
-
|
|
867
|
-
|
|
868
|
-
|
|
869
|
-
|
|
870
|
-
|
|
871
|
-
logger.info("[SERVER][" + cyan('SysCheck') + "] DISK " + yellow(used) + " GB used of " + green(total) + " GB (" + yellow(free) + " GB free)");
|
|
872
|
-
}
|
|
873
|
-
});
|
|
910
|
+
function _context_middleware() {
|
|
911
|
+
_context_middleware = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee(ctx, next) {
|
|
912
|
+
return _regeneratorRuntime().wrap(function _callee$(_context) {
|
|
913
|
+
while (1) switch (_context.prev = _context.next) {
|
|
914
|
+
case 0:
|
|
915
|
+
// Assign miolo stuff to ctx
|
|
916
|
+
ctx.miolo = mioloContext;
|
|
917
|
+
_context.next = 3;
|
|
918
|
+
return next();
|
|
919
|
+
case 3:
|
|
920
|
+
case "end":
|
|
921
|
+
return _context.stop();
|
|
922
|
+
}
|
|
923
|
+
}, _callee);
|
|
924
|
+
}));
|
|
925
|
+
return _context_middleware.apply(this, arguments);
|
|
874
926
|
}
|
|
875
|
-
|
|
876
|
-
|
|
877
|
-
|
|
878
|
-
function init_cron(logger) {
|
|
879
|
-
var sys_check_and_log = init_sys_check_and_log(logger);
|
|
880
|
-
new CronJob('30 * * * *', sys_check_and_log, null, true, 'Europe/Madrid');
|
|
881
|
-
}
|
|
927
|
+
app.use(context_middleware);
|
|
928
|
+
app.context.miolo = mioloContext;
|
|
929
|
+
};
|
|
882
930
|
|
|
883
931
|
var _if_options = function _if_options(http, field, callback) {
|
|
884
932
|
try {
|
|
@@ -910,7 +958,8 @@ var _proxy_options = function _proxy_options(options) {
|
|
|
910
958
|
};
|
|
911
959
|
return [tpath, toptions];
|
|
912
960
|
};
|
|
913
|
-
var init_headers_middleware = function init_headers_middleware(app, http
|
|
961
|
+
var init_headers_middleware = function init_headers_middleware(app, http) {
|
|
962
|
+
var logger = app.context.miolo.logger;
|
|
914
963
|
_if_options(http, 'cors', function (options) {
|
|
915
964
|
if (options == 'simple') {
|
|
916
965
|
logger.debug("Setting CORS the simple way");
|
|
@@ -956,7 +1005,13 @@ var init_body_middleware = function init_body_middleware(app) {
|
|
|
956
1005
|
return content_type == 'application/json' || content_type == 'text/html';
|
|
957
1006
|
},
|
|
958
1007
|
//threshold: 2048,
|
|
959
|
-
|
|
1008
|
+
gzip: {
|
|
1009
|
+
flush: constants.Z_SYNC_FLUSH
|
|
1010
|
+
},
|
|
1011
|
+
deflate: {
|
|
1012
|
+
flush: constants.Z_SYNC_FLUSH
|
|
1013
|
+
},
|
|
1014
|
+
br: false // disable brotli
|
|
960
1015
|
}));
|
|
961
1016
|
|
|
962
1017
|
// body parser - koa-better-body
|
|
@@ -970,7 +1025,7 @@ var init_body_middleware = function init_body_middleware(app) {
|
|
|
970
1025
|
// https://github.com/rkusa/koa-passport/issues/33#issuecomment-122611613
|
|
971
1026
|
// https://github.com/tunnckoCore/opensource/tree/master/%40packages/koa-better-body#options
|
|
972
1027
|
// {fields: 'body', files: 'body',}
|
|
973
|
-
// But this will cause errors on other packagers (for example, calustra
|
|
1028
|
+
// But this will cause errors on other packagers (for example, calustra/router)
|
|
974
1029
|
// 2.- but still need to know how dangerous it is to touch request.body (as by default,
|
|
975
1030
|
// koa-better-body is saving some async function in request.body)
|
|
976
1031
|
// We patch the .body on the `request` middleware
|
|
@@ -991,7 +1046,8 @@ var init_body_middleware = function init_body_middleware(app) {
|
|
|
991
1046
|
*/
|
|
992
1047
|
|
|
993
1048
|
var _ONLY_WARN = [401];
|
|
994
|
-
function init_catcher_middleware(app
|
|
1049
|
+
function init_catcher_middleware(app) {
|
|
1050
|
+
var logger = app.context.miolo.logger;
|
|
995
1051
|
function catcher_middleware(_x) {
|
|
996
1052
|
return _catcher_middleware.apply(this, arguments);
|
|
997
1053
|
}
|
|
@@ -1051,7 +1107,9 @@ function init_catcher_middleware(app, logger) {
|
|
|
1051
1107
|
app.context.onerror = catcher_middleware;
|
|
1052
1108
|
}
|
|
1053
1109
|
|
|
1054
|
-
var
|
|
1110
|
+
var __my_filename$2 = fileURLToPath(require('url').pathToFileURL(__filename).toString());
|
|
1111
|
+
var __my_dirname$2 = path.dirname(__my_filename$2);
|
|
1112
|
+
var fallback_favicon_path = path.resolve(__my_dirname$2, './miolo.ico');
|
|
1055
1113
|
var init_static_middleware = function init_static_middleware(app, config) {
|
|
1056
1114
|
var favicon = config.favicon,
|
|
1057
1115
|
folders = config.folders;
|
|
@@ -1173,7 +1231,9 @@ function init_session_middleware(app, config) {
|
|
|
1173
1231
|
app.use(koa_session(options, app));
|
|
1174
1232
|
}
|
|
1175
1233
|
|
|
1176
|
-
var
|
|
1234
|
+
var __my_filename$1 = fileURLToPath(require('url').pathToFileURL(__filename).toString());
|
|
1235
|
+
var __my_dirname$1 = path.dirname(__my_filename$1);
|
|
1236
|
+
var robots_txt = readFileSync(path.resolve(__my_dirname$1, './robots.txt'), 'utf8');
|
|
1177
1237
|
function init_route_robots(app) {
|
|
1178
1238
|
function robots(_x) {
|
|
1179
1239
|
return _robots.apply(this, arguments);
|
|
@@ -1227,8 +1287,10 @@ function init_route_catch_js_error(app, route) {
|
|
|
1227
1287
|
app.use(catch_js_error_router.routes());
|
|
1228
1288
|
}
|
|
1229
1289
|
|
|
1230
|
-
var
|
|
1231
|
-
var
|
|
1290
|
+
var __my_filename = fileURLToPath(require('url').pathToFileURL(__filename).toString());
|
|
1291
|
+
var __my_dirname = path.dirname(__my_filename);
|
|
1292
|
+
var indexHTMLPath = path.resolve(__my_dirname, 'fallback_index.html');
|
|
1293
|
+
var indexHTML = readFileSync(indexHTMLPath, 'utf8');
|
|
1232
1294
|
function init_route_html_render(app, html) {
|
|
1233
1295
|
// Server-side render
|
|
1234
1296
|
function html_render(_x) {
|
|
@@ -1267,31 +1329,33 @@ function miolo(_x, _x2, _x3) {
|
|
|
1267
1329
|
function _miolo() {
|
|
1268
1330
|
_miolo = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee(sconfig, render, callback) {
|
|
1269
1331
|
var _config$http, _config$auth, _config$auth2, _config$auth3;
|
|
1270
|
-
var
|
|
1332
|
+
var app, config, catcher_url, _yield$import, init_guest_auth_middleware, _yield$import2, init_basic_auth_middleware, _yield$import3, init_passport_auth_middleware, conn, extra_middlewares;
|
|
1271
1333
|
return _regeneratorRuntime().wrap(function _callee$(_context) {
|
|
1272
1334
|
while (1) switch (_context.prev = _context.next) {
|
|
1273
1335
|
case 0:
|
|
1274
|
-
// Init some pieces
|
|
1275
|
-
config = init_config(sconfig);
|
|
1276
|
-
|
|
1277
|
-
|
|
1278
|
-
|
|
1279
|
-
|
|
1280
|
-
|
|
1281
|
-
|
|
1336
|
+
app = new Koa(); // Init some pieces
|
|
1337
|
+
config = init_config(sconfig); //const emailer = init_emailer(config.mail.options, config.mail.defaults)
|
|
1338
|
+
//const logger = init_logger(config.log, emailer)
|
|
1339
|
+
//config.db.connection.options.log= logger
|
|
1340
|
+
// // attach to app calustra's db methods
|
|
1341
|
+
// initCalustraDbContext(app, config.db)
|
|
1342
|
+
//
|
|
1343
|
+
// // attach to app some custom miolo methods
|
|
1344
|
+
// app.context.miolo = {
|
|
1345
|
+
// config: {...config},
|
|
1346
|
+
// emailer,
|
|
1347
|
+
// logger,
|
|
1348
|
+
// db: app.context.db
|
|
1349
|
+
// }
|
|
1350
|
+
//
|
|
1282
1351
|
// attach to app some custom miolo methods
|
|
1283
|
-
app
|
|
1284
|
-
config: _extends({}, config),
|
|
1285
|
-
emailer: emailer,
|
|
1286
|
-
logger: logger,
|
|
1287
|
-
db: app.context.db
|
|
1288
|
-
};
|
|
1352
|
+
init_context_middleware(app, config);
|
|
1289
1353
|
|
|
1290
1354
|
// Compress and body parser
|
|
1291
1355
|
init_body_middleware(app);
|
|
1292
1356
|
|
|
1293
1357
|
// override koa's undocumented error handler
|
|
1294
|
-
init_catcher_middleware(app
|
|
1358
|
+
init_catcher_middleware(app);
|
|
1295
1359
|
|
|
1296
1360
|
// Serve static files
|
|
1297
1361
|
init_static_middleware(app, (_config$http = config.http) == null ? void 0 : _config$http["static"]);
|
|
@@ -1313,41 +1377,42 @@ function _miolo() {
|
|
|
1313
1377
|
|
|
1314
1378
|
// auth middleware
|
|
1315
1379
|
if (!(config != null && (_config$auth = config.auth) != null && _config$auth.guest)) {
|
|
1316
|
-
_context.next =
|
|
1380
|
+
_context.next = 17;
|
|
1317
1381
|
break;
|
|
1318
1382
|
}
|
|
1319
|
-
_context.next =
|
|
1383
|
+
_context.next = 14;
|
|
1320
1384
|
return Promise.resolve().then(function () { return guest; });
|
|
1321
|
-
case
|
|
1385
|
+
case 14:
|
|
1322
1386
|
_yield$import = _context.sent;
|
|
1323
1387
|
init_guest_auth_middleware = _yield$import.init_guest_auth_middleware;
|
|
1324
|
-
init_guest_auth_middleware(app, config.auth.guest, config == null ? void 0 : config.session
|
|
1325
|
-
case
|
|
1388
|
+
init_guest_auth_middleware(app, config.auth.guest, config == null ? void 0 : config.session);
|
|
1389
|
+
case 17:
|
|
1326
1390
|
if (!(config != null && (_config$auth2 = config.auth) != null && _config$auth2.basic)) {
|
|
1327
|
-
_context.next =
|
|
1391
|
+
_context.next = 23;
|
|
1328
1392
|
break;
|
|
1329
1393
|
}
|
|
1330
|
-
_context.next =
|
|
1394
|
+
_context.next = 20;
|
|
1331
1395
|
return Promise.resolve().then(function () { return basic; });
|
|
1332
|
-
case
|
|
1396
|
+
case 20:
|
|
1333
1397
|
_yield$import2 = _context.sent;
|
|
1334
1398
|
init_basic_auth_middleware = _yield$import2.init_basic_auth_middleware;
|
|
1335
1399
|
init_basic_auth_middleware(app, config.auth.basic);
|
|
1336
|
-
case
|
|
1400
|
+
case 23:
|
|
1337
1401
|
if (!(config != null && (_config$auth3 = config.auth) != null && _config$auth3.passport)) {
|
|
1338
|
-
_context.next =
|
|
1402
|
+
_context.next = 29;
|
|
1339
1403
|
break;
|
|
1340
1404
|
}
|
|
1341
|
-
_context.next =
|
|
1405
|
+
_context.next = 26;
|
|
1342
1406
|
return Promise.resolve().then(function () { return passport; });
|
|
1343
|
-
case
|
|
1407
|
+
case 26:
|
|
1344
1408
|
_yield$import3 = _context.sent;
|
|
1345
1409
|
init_passport_auth_middleware = _yield$import3.init_passport_auth_middleware;
|
|
1346
1410
|
init_passport_auth_middleware(app, config.auth.passport);
|
|
1347
|
-
case
|
|
1411
|
+
case 29:
|
|
1348
1412
|
// Routes to /crud
|
|
1349
1413
|
if (config != null && config.routes) {
|
|
1350
|
-
|
|
1414
|
+
conn = app.context.miolo.db.getConnection();
|
|
1415
|
+
initCalustraRouter(app, conn, config.routes);
|
|
1351
1416
|
}
|
|
1352
1417
|
// Socket.io
|
|
1353
1418
|
// const io= init_socket(logger)
|
|
@@ -1360,7 +1425,7 @@ function _miolo() {
|
|
|
1360
1425
|
}
|
|
1361
1426
|
|
|
1362
1427
|
// CORS and other headers
|
|
1363
|
-
init_headers_middleware(app, config.http
|
|
1428
|
+
init_headers_middleware(app, config.http);
|
|
1364
1429
|
|
|
1365
1430
|
// Middleware for html render
|
|
1366
1431
|
if (render == undefined || render.html != undefined) {
|
|
@@ -1369,14 +1434,14 @@ function _miolo() {
|
|
|
1369
1434
|
app.use(render.middleware);
|
|
1370
1435
|
}
|
|
1371
1436
|
app.listen(config.http.port, config.http.hostname, function () {
|
|
1372
|
-
logger.info("miolo is listening on " + config.http.hostname + ":" + config.http.port);
|
|
1373
|
-
init_cron(logger);
|
|
1437
|
+
app.context.miolo.logger.info("miolo is listening on " + config.http.hostname + ":" + config.http.port);
|
|
1438
|
+
init_cron(app.context.miolo.logger);
|
|
1374
1439
|
if (callback != undefined) {
|
|
1375
1440
|
callback();
|
|
1376
1441
|
}
|
|
1377
1442
|
});
|
|
1378
1443
|
return _context.abrupt("return", app);
|
|
1379
|
-
case
|
|
1444
|
+
case 36:
|
|
1380
1445
|
case "end":
|
|
1381
1446
|
return _context.stop();
|
|
1382
1447
|
}
|
|
@@ -1385,118 +1450,165 @@ function _miolo() {
|
|
|
1385
1450
|
return _miolo.apply(this, arguments);
|
|
1386
1451
|
}
|
|
1387
1452
|
|
|
1388
|
-
|
|
1389
|
-
|
|
1390
|
-
|
|
1391
|
-
|
|
1392
|
-
|
|
1453
|
+
var Context = /*#__PURE__*/React.createContext();
|
|
1454
|
+
|
|
1455
|
+
var AppContext = function AppContext(_ref) {
|
|
1456
|
+
var context = _ref.context,
|
|
1457
|
+
children = _ref.children;
|
|
1458
|
+
var _useState = useState(context),
|
|
1459
|
+
innerContext = _useState[0],
|
|
1460
|
+
setInnerContext = _useState[1];
|
|
1461
|
+
useEffect(function () {
|
|
1462
|
+
setInnerContext(context);
|
|
1463
|
+
}, [context]);
|
|
1464
|
+
return /*#__PURE__*/React.createElement(Context.Provider, {
|
|
1465
|
+
value: {
|
|
1466
|
+
context: innerContext,
|
|
1467
|
+
setContext: setInnerContext
|
|
1468
|
+
}
|
|
1469
|
+
}, children);
|
|
1470
|
+
};
|
|
1471
|
+
|
|
1472
|
+
var AppSsr = function AppSsr(_ref) {
|
|
1473
|
+
var url = _ref.url,
|
|
1474
|
+
context = _ref.context,
|
|
1475
|
+
children = _ref.children;
|
|
1476
|
+
return /*#__PURE__*/React.createElement(StaticRouter, {
|
|
1477
|
+
location: url
|
|
1478
|
+
}, /*#__PURE__*/React.createElement(AppContext, {
|
|
1479
|
+
context: context
|
|
1480
|
+
}, children));
|
|
1481
|
+
};
|
|
1482
|
+
|
|
1483
|
+
var ErrMessage = function ErrMessage(_ref) {
|
|
1484
|
+
_ref.ctx;
|
|
1485
|
+
var error = _ref.error;
|
|
1486
|
+
return /*#__PURE__*/React.createElement("div", null, "[MIOLO-SERVER_TOOLS] Missing SSR renderer: " + error.toString());
|
|
1487
|
+
};
|
|
1488
|
+
|
|
1489
|
+
var html = "\n\t\t<!DOCTYPE html>\n\t\t<html lang=\"en\">\n\t\t<head>\n\t\t\t<meta charset=\"utf-8\">\n\t\t\t<meta http-equiv=\"X-UA-Compatible\" content=\"IE=edge\">\n\t\t\t<title>miolo</title>\n\t\t\t<meta name=\"viewport\" content=\"width=device-width, initial-scale=1\">\n\t\t\t<meta name=\"description\" content=\"miolo\" />\n\t\t\t<meta name=\"keywords\" content=\"miolo web\" />\n\t\t\t<meta name=\"author\" content=\"miolo.afialapis.com\" />\n\n\t\t\t<!-- Touch Icons - iOS and Android 2.1+ 180x180 pixels in size. --> \n\t\t\t<!--<link rel=\"apple-touch-icon-precomposed\" href=\"/favicon.ico\"/>-->\n\t\t\t<!-- Firefox, Chrome, Safari, IE 11+ and Opera. 196x196 pixels in size. -->\n\t\t\t<link rel=\"icon\" href=\"/favicon.ico\"/>\n\n\t\t\t{styles}\n\n\t\t\t<script>\n\t\t\t\twindow.__CONTEXT = {context}\n\t\t\t</script>\t\t\n\t\t</head>\n\n\t\t<body>\n\t\t\t<div id=\"root\">{children}</div>\n\t\t\t{bundle}\n\t\t</body>\n\t\t</html>\n ";
|
|
1490
|
+
|
|
1491
|
+
function init_render_middleware(loader, renderer, options) {
|
|
1492
|
+
// parse options
|
|
1493
|
+
var html$1 = html,
|
|
1494
|
+
port = 8000,
|
|
1495
|
+
use_css = true;
|
|
1496
|
+
try {
|
|
1497
|
+
if ((options == null ? void 0 : options.html) != undefined) {
|
|
1498
|
+
html$1 = options.html;
|
|
1499
|
+
}
|
|
1500
|
+
} catch (_) {}
|
|
1501
|
+
try {
|
|
1502
|
+
if ((options == null ? void 0 : options.port) != undefined) {
|
|
1503
|
+
if (!isNaN(parseInt(options.port))) {
|
|
1504
|
+
port = parseInt(options.port);
|
|
1505
|
+
}
|
|
1506
|
+
}
|
|
1507
|
+
} catch (_) {}
|
|
1508
|
+
try {
|
|
1509
|
+
use_css = (options == null ? void 0 : options.css) !== false;
|
|
1510
|
+
} catch (_) {}
|
|
1511
|
+
var bundleURL = '';
|
|
1512
|
+
var cssURL = use_css ? '' : '';
|
|
1513
|
+
var def_renderer = function def_renderer(ctx) {
|
|
1393
1514
|
try {
|
|
1394
|
-
|
|
1395
|
-
} catch (
|
|
1396
|
-
|
|
1515
|
+
return renderer(ctx);
|
|
1516
|
+
} catch (error) {
|
|
1517
|
+
ctx.miolo.logger.error('Missing renderer in the render middleware');
|
|
1518
|
+
return ErrMessage({
|
|
1519
|
+
ctx: ctx,
|
|
1520
|
+
error: error
|
|
1521
|
+
});
|
|
1397
1522
|
}
|
|
1398
|
-
|
|
1399
|
-
|
|
1400
|
-
|
|
1401
|
-
|
|
1402
|
-
var _setKey = promisify(client.set).bind(client);
|
|
1403
|
-
var _delKey = promisify(client.del).bind(client);
|
|
1404
|
-
function redisGet(_x) {
|
|
1405
|
-
return _redisGet.apply(this, arguments);
|
|
1406
|
-
}
|
|
1407
|
-
function _redisGet() {
|
|
1408
|
-
_redisGet = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee(key) {
|
|
1523
|
+
};
|
|
1524
|
+
var def_loader = /*#__PURE__*/function () {
|
|
1525
|
+
var _ref = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee(ctx) {
|
|
1526
|
+
var res;
|
|
1409
1527
|
return _regeneratorRuntime().wrap(function _callee$(_context) {
|
|
1410
1528
|
while (1) switch (_context.prev = _context.next) {
|
|
1411
1529
|
case 0:
|
|
1412
|
-
|
|
1413
|
-
|
|
1414
|
-
|
|
1415
|
-
return
|
|
1416
|
-
case
|
|
1530
|
+
res = {};
|
|
1531
|
+
_context.prev = 1;
|
|
1532
|
+
_context.next = 4;
|
|
1533
|
+
return loader(ctx);
|
|
1534
|
+
case 4:
|
|
1535
|
+
res = _context.sent;
|
|
1536
|
+
_context.next = 11;
|
|
1537
|
+
break;
|
|
1538
|
+
case 7:
|
|
1539
|
+
_context.prev = 7;
|
|
1540
|
+
_context.t0 = _context["catch"](1);
|
|
1541
|
+
ctx.miolo.logger.error('Error produced by loader in the render middleware');
|
|
1542
|
+
ctx.miolo.logger.error(_context.t0);
|
|
1543
|
+
case 11:
|
|
1544
|
+
return _context.abrupt("return", res);
|
|
1545
|
+
case 12:
|
|
1417
1546
|
case "end":
|
|
1418
1547
|
return _context.stop();
|
|
1419
1548
|
}
|
|
1420
|
-
}, _callee);
|
|
1549
|
+
}, _callee, null, [[1, 7]]);
|
|
1421
1550
|
}));
|
|
1422
|
-
return
|
|
1423
|
-
|
|
1424
|
-
|
|
1425
|
-
|
|
1551
|
+
return function def_loader(_x) {
|
|
1552
|
+
return _ref.apply(this, arguments);
|
|
1553
|
+
};
|
|
1554
|
+
}();
|
|
1555
|
+
function render_middleware(_x2) {
|
|
1556
|
+
return _render_middleware.apply(this, arguments);
|
|
1426
1557
|
}
|
|
1427
|
-
function
|
|
1428
|
-
|
|
1429
|
-
var
|
|
1558
|
+
function _render_middleware() {
|
|
1559
|
+
_render_middleware = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee2(ctx) {
|
|
1560
|
+
var ssr_data, isAuthed, user, context, ssr_html, parsed_html;
|
|
1430
1561
|
return _regeneratorRuntime().wrap(function _callee2$(_context2) {
|
|
1431
1562
|
while (1) switch (_context2.prev = _context2.next) {
|
|
1432
1563
|
case 0:
|
|
1433
1564
|
_context2.next = 2;
|
|
1434
|
-
return
|
|
1565
|
+
return def_loader(ctx);
|
|
1435
1566
|
case 2:
|
|
1436
|
-
|
|
1437
|
-
|
|
1438
|
-
|
|
1567
|
+
ssr_data = _context2.sent;
|
|
1568
|
+
//const ssr_comp = def_renderer(ctx)
|
|
1569
|
+
isAuthed = false;
|
|
1570
|
+
try {
|
|
1571
|
+
isAuthed = (ctx == null ? void 0 : ctx.isAuthenticated()) === true;
|
|
1572
|
+
} catch (e) {}
|
|
1573
|
+
try {
|
|
1574
|
+
if (!isAuthed) {
|
|
1575
|
+
isAuthed = ctx.user.name === 'guest' && ctx.user.token != undefined;
|
|
1576
|
+
}
|
|
1577
|
+
} catch (e) {}
|
|
1578
|
+
user = undefined;
|
|
1579
|
+
try {
|
|
1580
|
+
if (ctx.state.user != undefined) {
|
|
1581
|
+
user = ctx.state.user;
|
|
1582
|
+
}
|
|
1583
|
+
} catch (_) {}
|
|
1584
|
+
try {
|
|
1585
|
+
if (ctx.user != undefined) {
|
|
1586
|
+
user = ctx.user;
|
|
1587
|
+
}
|
|
1588
|
+
} catch (_) {}
|
|
1589
|
+
context = {
|
|
1590
|
+
user: user,
|
|
1591
|
+
authenticated: isAuthed,
|
|
1592
|
+
ssr_data: ssr_data,
|
|
1593
|
+
extra: ctx == null ? void 0 : ctx.extra
|
|
1594
|
+
};
|
|
1595
|
+
ssr_html = renderToString( /*#__PURE__*/React.createElement(AppSsr, {
|
|
1596
|
+
url: ctx.url,
|
|
1597
|
+
context: context
|
|
1598
|
+
}, function () {
|
|
1599
|
+
return def_renderer(ctx);
|
|
1600
|
+
}));
|
|
1601
|
+
parsed_html = html$1.replace('{context}', JSON.stringify(context, null, 2)).replace(/{bundleURL}/g, bundleURL).replace('{children}', ssr_html).replace('{styles}', cssURL).replace('{bundle}', bundleURL);
|
|
1602
|
+
ctx.body = parsed_html;
|
|
1603
|
+
case 13:
|
|
1439
1604
|
case "end":
|
|
1440
1605
|
return _context2.stop();
|
|
1441
1606
|
}
|
|
1442
1607
|
}, _callee2);
|
|
1443
1608
|
}));
|
|
1444
|
-
return
|
|
1445
|
-
}
|
|
1446
|
-
function redisSet(_x3, _x4, _x5) {
|
|
1447
|
-
return _redisSet.apply(this, arguments);
|
|
1448
|
-
}
|
|
1449
|
-
function _redisSet() {
|
|
1450
|
-
_redisSet = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee3(key, value, expiration) {
|
|
1451
|
-
var r;
|
|
1452
|
-
return _regeneratorRuntime().wrap(function _callee3$(_context3) {
|
|
1453
|
-
while (1) switch (_context3.prev = _context3.next) {
|
|
1454
|
-
case 0:
|
|
1455
|
-
if (expiration === void 0) {
|
|
1456
|
-
expiration = 86400;
|
|
1457
|
-
}
|
|
1458
|
-
_context3.next = 3;
|
|
1459
|
-
return _setKey(key, value, 'EX', expiration);
|
|
1460
|
-
case 3:
|
|
1461
|
-
r = _context3.sent;
|
|
1462
|
-
return _context3.abrupt("return", r == 'OK' ? true : false);
|
|
1463
|
-
case 5:
|
|
1464
|
-
case "end":
|
|
1465
|
-
return _context3.stop();
|
|
1466
|
-
}
|
|
1467
|
-
}, _callee3);
|
|
1468
|
-
}));
|
|
1469
|
-
return _redisSet.apply(this, arguments);
|
|
1470
|
-
}
|
|
1471
|
-
function redisDel(_x6) {
|
|
1472
|
-
return _redisDel.apply(this, arguments);
|
|
1609
|
+
return _render_middleware.apply(this, arguments);
|
|
1473
1610
|
}
|
|
1474
|
-
|
|
1475
|
-
_redisDel = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee4(key) {
|
|
1476
|
-
var r;
|
|
1477
|
-
return _regeneratorRuntime().wrap(function _callee4$(_context4) {
|
|
1478
|
-
while (1) switch (_context4.prev = _context4.next) {
|
|
1479
|
-
case 0:
|
|
1480
|
-
_context4.next = 2;
|
|
1481
|
-
return _delKey(key);
|
|
1482
|
-
case 2:
|
|
1483
|
-
r = _context4.sent;
|
|
1484
|
-
return _context4.abrupt("return", r >= 1 ? true : false);
|
|
1485
|
-
case 4:
|
|
1486
|
-
case "end":
|
|
1487
|
-
return _context4.stop();
|
|
1488
|
-
}
|
|
1489
|
-
}, _callee4);
|
|
1490
|
-
}));
|
|
1491
|
-
return _redisDel.apply(this, arguments);
|
|
1492
|
-
}
|
|
1493
|
-
var cacher = {
|
|
1494
|
-
get: redisGet,
|
|
1495
|
-
exists: redisExists,
|
|
1496
|
-
set: redisSet,
|
|
1497
|
-
del: redisDel
|
|
1498
|
-
};
|
|
1499
|
-
return cacher;
|
|
1611
|
+
return render_middleware;
|
|
1500
1612
|
}
|
|
1501
1613
|
|
|
1502
1614
|
function _guest_token_make_with_jwt(session, logger) {
|
|
@@ -1525,7 +1637,8 @@ function _get_cookie_properties(session) {
|
|
|
1525
1637
|
httpOnly: false
|
|
1526
1638
|
};
|
|
1527
1639
|
}
|
|
1528
|
-
var init_guest_auth_middleware = function init_guest_auth_middleware(app, options, session
|
|
1640
|
+
var init_guest_auth_middleware = function init_guest_auth_middleware(app, options, session) {
|
|
1641
|
+
var logger = app.context.miolo.logger;
|
|
1529
1642
|
var _make_guest_token = function _make_guest_token() {
|
|
1530
1643
|
try {
|
|
1531
1644
|
var make_guest_token = options.make_guest_token;
|
|
@@ -1770,4 +1883,4 @@ var passport = /*#__PURE__*/Object.freeze({
|
|
|
1770
1883
|
init_passport_auth_middleware: init_passport_auth_middleware
|
|
1771
1884
|
});
|
|
1772
1885
|
|
|
1773
|
-
export {
|
|
1886
|
+
export { AppSsr, init_render_middleware, miolo };
|