miolo 0.0.21 → 0.0.24
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/lib/config/defaults.js +26 -29
- package/lib/server/index.js +5 -14
- package/lib/server/routes/calustra.js +30 -0
- package/package.json +3 -3
- package/src/config/defaults.js +25 -29
- package/src/server/index.js +3 -10
- package/src/server/routes/calustra.js +14 -0
- package/lib/server/routes/crud.js +0 -53
- package/lib/server/routes/queries.js +0 -87
- package/src/server/routes/crud.js +0 -29
- package/src/server/routes/queries.js +0 -70
package/lib/config/defaults.js
CHANGED
|
@@ -68,35 +68,32 @@ module.exports = {
|
|
|
68
68
|
log: 'info'
|
|
69
69
|
}
|
|
70
70
|
},
|
|
71
|
-
routes: {
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
//
|
|
87
|
-
//
|
|
88
|
-
//
|
|
89
|
-
//
|
|
90
|
-
//
|
|
91
|
-
//
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
// }
|
|
98
|
-
// ]
|
|
99
|
-
// }
|
|
71
|
+
routes: {
|
|
72
|
+
body_field: undefined,
|
|
73
|
+
getUserId: ctx => {
|
|
74
|
+
try {
|
|
75
|
+
return ctx.state.user.id;
|
|
76
|
+
} catch (e) {}
|
|
77
|
+
|
|
78
|
+
var uid = ctx.headers['user-id'];
|
|
79
|
+
|
|
80
|
+
if (uid != undefined) {
|
|
81
|
+
return uid;
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
return undefined;
|
|
85
|
+
},
|
|
86
|
+
// authUser: {
|
|
87
|
+
// require: false, // true / false / 'read-only'
|
|
88
|
+
// action: 'redirect', // 'error'
|
|
89
|
+
// redirect_url: '/',
|
|
90
|
+
// error_code: 401
|
|
91
|
+
// },
|
|
92
|
+
crud: {
|
|
93
|
+
prefix: '',
|
|
94
|
+
routes: '*'
|
|
95
|
+
},
|
|
96
|
+
queries: undefined
|
|
100
97
|
},
|
|
101
98
|
cacher: {
|
|
102
99
|
redis: {
|
package/lib/server/index.js
CHANGED
|
@@ -49,7 +49,7 @@ function miolo(_x, _x2, _x3) {
|
|
|
49
49
|
|
|
50
50
|
function _miolo() {
|
|
51
51
|
_miolo = _asyncToGenerator(function* (sconfig, render, callback) {
|
|
52
|
-
var _config$http, _config$auth, _config$auth2
|
|
52
|
+
var _config$http, _config$auth, _config$auth2;
|
|
53
53
|
|
|
54
54
|
// Init some pieces
|
|
55
55
|
var config = (0, _config.init_config)(sconfig);
|
|
@@ -96,21 +96,12 @@ function _miolo() {
|
|
|
96
96
|
} // Routes to /crud
|
|
97
97
|
|
|
98
98
|
|
|
99
|
-
if (config !== null && config !== void 0 &&
|
|
99
|
+
if (config !== null && config !== void 0 && config.routes) {
|
|
100
100
|
var {
|
|
101
|
-
|
|
102
|
-
} = require("./routes/
|
|
101
|
+
init_calustra_router
|
|
102
|
+
} = require("./routes/calustra");
|
|
103
103
|
|
|
104
|
-
yield
|
|
105
|
-
} // Queries routes
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
if (config !== null && config !== void 0 && (_config$routes2 = config.routes) !== null && _config$routes2 !== void 0 && _config$routes2.queries) {
|
|
109
|
-
var {
|
|
110
|
-
init_queries_router
|
|
111
|
-
} = require("./routes/queries");
|
|
112
|
-
|
|
113
|
-
yield init_queries_router(app, conn, config.routes.queries);
|
|
104
|
+
yield init_calustra_router(app, conn, config.routes);
|
|
114
105
|
} // Socket.io
|
|
115
106
|
// const io= init_socket(logger)
|
|
116
107
|
// io.attach(app)
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.init_calustra_router = init_calustra_router;
|
|
7
|
+
|
|
8
|
+
var _calustraRouter = _interopRequireDefault(require("calustra-router"));
|
|
9
|
+
|
|
10
|
+
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
11
|
+
|
|
12
|
+
function asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) { try { var info = gen[key](arg); var value = info.value; } catch (error) { reject(error); return; } if (info.done) { resolve(value); } else { Promise.resolve(value).then(_next, _throw); } }
|
|
13
|
+
|
|
14
|
+
function _asyncToGenerator(fn) { return function () { var self = this, args = arguments; return new Promise(function (resolve, reject) { var gen = fn.apply(self, args); function _next(value) { asyncGeneratorStep(gen, resolve, reject, _next, _throw, "next", value); } function _throw(err) { asyncGeneratorStep(gen, resolve, reject, _next, _throw, "throw", err); } _next(undefined); }); }; }
|
|
15
|
+
|
|
16
|
+
function init_calustra_router(_x, _x2, _x3) {
|
|
17
|
+
return _init_calustra_router.apply(this, arguments);
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
function _init_calustra_router() {
|
|
21
|
+
_init_calustra_router = _asyncToGenerator(function* (app, conn, config) {
|
|
22
|
+
if (!config) {
|
|
23
|
+
return undefined;
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
var router = yield (0, _calustraRouter.default)(conn, config);
|
|
27
|
+
app.use(router.routes());
|
|
28
|
+
});
|
|
29
|
+
return _init_calustra_router.apply(this, arguments);
|
|
30
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "miolo",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.24",
|
|
4
4
|
"description": "miolo",
|
|
5
5
|
"main": "lib/index.js",
|
|
6
6
|
"author": "Afialapis <info@afialapis.com>",
|
|
@@ -14,8 +14,8 @@
|
|
|
14
14
|
"assign-deep": "^1.0.1",
|
|
15
15
|
"babel-plugin-module-resolver": "^4.1.0",
|
|
16
16
|
"basic-auth": "^2.0.1",
|
|
17
|
-
"calustra": "0.0.
|
|
18
|
-
"calustra-router": "0.0.
|
|
17
|
+
"calustra": "0.0.26",
|
|
18
|
+
"calustra-router": "0.0.26",
|
|
19
19
|
"cron": "^1.8.2",
|
|
20
20
|
"diskspace": "^2.0.0",
|
|
21
21
|
"eslint": "^8.9.0",
|
package/src/config/defaults.js
CHANGED
|
@@ -63,35 +63,31 @@ module.exports= {
|
|
|
63
63
|
},
|
|
64
64
|
},
|
|
65
65
|
routes: {
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
//
|
|
80
|
-
//
|
|
81
|
-
//
|
|
82
|
-
//
|
|
83
|
-
//
|
|
84
|
-
//
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
// callback: method_receiving_params_ctx_conn
|
|
92
|
-
// }
|
|
93
|
-
// ]
|
|
94
|
-
// }
|
|
66
|
+
body_field: undefined,
|
|
67
|
+
|
|
68
|
+
getUserId: (ctx) => {
|
|
69
|
+
try {
|
|
70
|
+
return ctx.state.user.id
|
|
71
|
+
} catch(e) {}
|
|
72
|
+
let uid= ctx.headers['user-id']
|
|
73
|
+
if (uid!=undefined) {
|
|
74
|
+
return uid
|
|
75
|
+
}
|
|
76
|
+
return undefined
|
|
77
|
+
},
|
|
78
|
+
|
|
79
|
+
// authUser: {
|
|
80
|
+
// require: false, // true / false / 'read-only'
|
|
81
|
+
// action: 'redirect', // 'error'
|
|
82
|
+
// redirect_url: '/',
|
|
83
|
+
// error_code: 401
|
|
84
|
+
// },
|
|
85
|
+
|
|
86
|
+
crud: {
|
|
87
|
+
prefix: '',
|
|
88
|
+
routes: '*'
|
|
89
|
+
},
|
|
90
|
+
queries: undefined
|
|
95
91
|
},
|
|
96
92
|
cacher: {
|
|
97
93
|
redis: {
|
package/src/server/index.js
CHANGED
|
@@ -70,17 +70,10 @@ async function miolo(sconfig, render, callback) {
|
|
|
70
70
|
}
|
|
71
71
|
|
|
72
72
|
// Routes to /crud
|
|
73
|
-
if (config?.routes
|
|
74
|
-
const {
|
|
75
|
-
await
|
|
73
|
+
if (config?.routes) {
|
|
74
|
+
const {init_calustra_router} = require('./routes/calustra')
|
|
75
|
+
await init_calustra_router(app, conn, config.routes)
|
|
76
76
|
}
|
|
77
|
-
|
|
78
|
-
// Queries routes
|
|
79
|
-
if (config?.routes?.queries) {
|
|
80
|
-
const {init_queries_router} = require('./routes/queries')
|
|
81
|
-
await init_queries_router(app, conn, config.routes.queries)
|
|
82
|
-
}
|
|
83
|
-
|
|
84
77
|
// Socket.io
|
|
85
78
|
// const io= init_socket(logger)
|
|
86
79
|
// io.attach(app)
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import calustraRouter from 'calustra-router'
|
|
2
|
+
|
|
3
|
+
async function init_calustra_router (app, conn, config) {
|
|
4
|
+
|
|
5
|
+
if (! config) {
|
|
6
|
+
return undefined
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
const router= await calustraRouter(conn, config)
|
|
10
|
+
app.use(router.routes())
|
|
11
|
+
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
export {init_calustra_router}
|
|
@@ -1,53 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, "__esModule", {
|
|
4
|
-
value: true
|
|
5
|
-
});
|
|
6
|
-
exports.init_crud_router = init_crud_router;
|
|
7
|
-
|
|
8
|
-
var _calustraRouter = _interopRequireDefault(require("calustra-router"));
|
|
9
|
-
|
|
10
|
-
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
11
|
-
|
|
12
|
-
function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
|
|
13
|
-
|
|
14
|
-
function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { _defineProperty(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; }
|
|
15
|
-
|
|
16
|
-
function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
|
|
17
|
-
|
|
18
|
-
function asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) { try { var info = gen[key](arg); var value = info.value; } catch (error) { reject(error); return; } if (info.done) { resolve(value); } else { Promise.resolve(value).then(_next, _throw); } }
|
|
19
|
-
|
|
20
|
-
function _asyncToGenerator(fn) { return function () { var self = this, args = arguments; return new Promise(function (resolve, reject) { var gen = fn.apply(self, args); function _next(value) { asyncGeneratorStep(gen, resolve, reject, _next, _throw, "next", value); } function _throw(err) { asyncGeneratorStep(gen, resolve, reject, _next, _throw, "throw", err); } _next(undefined); }); }; }
|
|
21
|
-
|
|
22
|
-
function init_crud_router(_x, _x2, _x3) {
|
|
23
|
-
return _init_crud_router.apply(this, arguments);
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
function _init_crud_router() {
|
|
27
|
-
_init_crud_router = _asyncToGenerator(function* (app, conn, config) {
|
|
28
|
-
if (!config) {
|
|
29
|
-
return undefined;
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
var routerOptions = _objectSpread({
|
|
33
|
-
body_field: undefined,
|
|
34
|
-
get_user_id: ctx => {
|
|
35
|
-
try {
|
|
36
|
-
return ctx.state.user.id;
|
|
37
|
-
} catch (e) {}
|
|
38
|
-
|
|
39
|
-
var uid = ctx.headers['user-id'];
|
|
40
|
-
|
|
41
|
-
if (uid != undefined) {
|
|
42
|
-
return uid;
|
|
43
|
-
}
|
|
44
|
-
|
|
45
|
-
return undefined;
|
|
46
|
-
}
|
|
47
|
-
}, config.options);
|
|
48
|
-
|
|
49
|
-
var router = yield (0, _calustraRouter.default)(conn, config.routes, config.path, 'public', routerOptions);
|
|
50
|
-
app.use(router.routes());
|
|
51
|
-
});
|
|
52
|
-
return _init_crud_router.apply(this, arguments);
|
|
53
|
-
}
|
|
@@ -1,87 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, "__esModule", {
|
|
4
|
-
value: true
|
|
5
|
-
});
|
|
6
|
-
exports.init_queries_router = init_queries_router;
|
|
7
|
-
|
|
8
|
-
var _router = _interopRequireDefault(require("@koa/router"));
|
|
9
|
-
|
|
10
|
-
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
11
|
-
|
|
12
|
-
function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
|
|
13
|
-
|
|
14
|
-
function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { _defineProperty(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; }
|
|
15
|
-
|
|
16
|
-
function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
|
|
17
|
-
|
|
18
|
-
function asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) { try { var info = gen[key](arg); var value = info.value; } catch (error) { reject(error); return; } if (info.done) { resolve(value); } else { Promise.resolve(value).then(_next, _throw); } }
|
|
19
|
-
|
|
20
|
-
function _asyncToGenerator(fn) { return function () { var self = this, args = arguments; return new Promise(function (resolve, reject) { var gen = fn.apply(self, args); function _next(value) { asyncGeneratorStep(gen, resolve, reject, _next, _throw, "next", value); } function _throw(err) { asyncGeneratorStep(gen, resolve, reject, _next, _throw, "throw", err); } _next(undefined); }); }; }
|
|
21
|
-
|
|
22
|
-
function _check_auth(ctx, auth, method) {
|
|
23
|
-
var check = auth.require === true || auth.require === 'read-only' && method === 'POST';
|
|
24
|
-
|
|
25
|
-
if (check) {
|
|
26
|
-
var uid = undefined;
|
|
27
|
-
|
|
28
|
-
try {
|
|
29
|
-
uid = ctx.state.user.id;
|
|
30
|
-
} catch (e) {}
|
|
31
|
-
|
|
32
|
-
if (uid === undefined) {
|
|
33
|
-
if (auth.action == 'error') {
|
|
34
|
-
ctx.miolo.logger.error("Unauthorized access. Throwing error ".concat(auth.error_code || 401));
|
|
35
|
-
return ctx.throw(auth.error_code || 401, null, {});
|
|
36
|
-
} else {
|
|
37
|
-
ctx.miolo.logger.error("Unauthorized access. Redirecting to ".concat(auth.redirect_path || '/'));
|
|
38
|
-
ctx.redirect(auth.redirect_path || '/');
|
|
39
|
-
}
|
|
40
|
-
}
|
|
41
|
-
}
|
|
42
|
-
}
|
|
43
|
-
|
|
44
|
-
function init_queries_router(_x, _x2, _x3) {
|
|
45
|
-
return _init_queries_router.apply(this, arguments);
|
|
46
|
-
}
|
|
47
|
-
|
|
48
|
-
function _init_queries_router() {
|
|
49
|
-
_init_queries_router = _asyncToGenerator(function* (app, conn, queries) {
|
|
50
|
-
var routes = (queries === null || queries === void 0 ? void 0 : queries.routes) || [];
|
|
51
|
-
|
|
52
|
-
if (routes.length == 0) {
|
|
53
|
-
return;
|
|
54
|
-
}
|
|
55
|
-
|
|
56
|
-
var options = (queries === null || queries === void 0 ? void 0 : queries.options) || {};
|
|
57
|
-
var global_auth = (options === null || options === void 0 ? void 0 : options.auth) || {
|
|
58
|
-
require: false
|
|
59
|
-
};
|
|
60
|
-
var router = new _router.default();
|
|
61
|
-
routes.map(route => {
|
|
62
|
-
function route_callback(_x4) {
|
|
63
|
-
return _route_callback.apply(this, arguments);
|
|
64
|
-
}
|
|
65
|
-
|
|
66
|
-
function _route_callback() {
|
|
67
|
-
_route_callback = _asyncToGenerator(function* (ctx) {
|
|
68
|
-
var auth = _objectSpread(_objectSpread({}, global_auth), route.auth || {});
|
|
69
|
-
|
|
70
|
-
_check_auth(ctx, auth, route.method);
|
|
71
|
-
|
|
72
|
-
var result = yield route.callback(ctx, conn);
|
|
73
|
-
return result;
|
|
74
|
-
});
|
|
75
|
-
return _route_callback.apply(this, arguments);
|
|
76
|
-
}
|
|
77
|
-
|
|
78
|
-
if (route.method == 'POST') {
|
|
79
|
-
router.post(route.path, route_callback);
|
|
80
|
-
} else {
|
|
81
|
-
router.get(route.path, route_callback);
|
|
82
|
-
}
|
|
83
|
-
});
|
|
84
|
-
app.use(router.routes());
|
|
85
|
-
});
|
|
86
|
-
return _init_queries_router.apply(this, arguments);
|
|
87
|
-
}
|
|
@@ -1,29 +0,0 @@
|
|
|
1
|
-
import calustraRouter from 'calustra-router'
|
|
2
|
-
|
|
3
|
-
async function init_crud_router (app, conn, config) {
|
|
4
|
-
|
|
5
|
-
if (! config) {
|
|
6
|
-
return undefined
|
|
7
|
-
}
|
|
8
|
-
|
|
9
|
-
const routerOptions= {
|
|
10
|
-
body_field: undefined,
|
|
11
|
-
get_user_id: (ctx) => {
|
|
12
|
-
try {
|
|
13
|
-
return ctx.state.user.id
|
|
14
|
-
} catch(e) {}
|
|
15
|
-
let uid= ctx.headers['user-id']
|
|
16
|
-
if (uid!=undefined) {
|
|
17
|
-
return uid
|
|
18
|
-
}
|
|
19
|
-
return undefined
|
|
20
|
-
},
|
|
21
|
-
...config.options
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
const router= await calustraRouter(conn, config.routes, config.path, 'public', routerOptions)
|
|
25
|
-
app.use(router.routes())
|
|
26
|
-
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
export {init_crud_router}
|
|
@@ -1,70 +0,0 @@
|
|
|
1
|
-
import Router from '@koa/router'
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
function _check_auth(ctx, auth, method) {
|
|
5
|
-
const check= (auth.require===true) || (auth.require==='read-only' && method==='POST')
|
|
6
|
-
|
|
7
|
-
if (check) {
|
|
8
|
-
let uid= undefined
|
|
9
|
-
try {
|
|
10
|
-
uid= ctx.state.user.id
|
|
11
|
-
} catch(e) {}
|
|
12
|
-
|
|
13
|
-
if (uid===undefined) {
|
|
14
|
-
|
|
15
|
-
if (auth.action=='error') {
|
|
16
|
-
|
|
17
|
-
ctx.miolo.logger.error(`Unauthorized access. Throwing error ${auth.error_code || 401}`)
|
|
18
|
-
return ctx.throw(
|
|
19
|
-
auth.error_code || 401,
|
|
20
|
-
null,
|
|
21
|
-
{}
|
|
22
|
-
)
|
|
23
|
-
|
|
24
|
-
} else {
|
|
25
|
-
ctx.miolo.logger.error(`Unauthorized access. Redirecting to ${auth.redirect_path || '/'}`)
|
|
26
|
-
ctx.redirect(auth.redirect_path || '/')
|
|
27
|
-
}
|
|
28
|
-
}
|
|
29
|
-
}
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
async function init_queries_router (app, conn, queries) {
|
|
34
|
-
|
|
35
|
-
const routes= queries?.routes || []
|
|
36
|
-
if (routes.length==0) {
|
|
37
|
-
return
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
const options= queries?.options || {}
|
|
41
|
-
const global_auth = options?.auth || {require: false}
|
|
42
|
-
|
|
43
|
-
const router = new Router()
|
|
44
|
-
|
|
45
|
-
routes.map(route => {
|
|
46
|
-
|
|
47
|
-
async function route_callback(ctx) {
|
|
48
|
-
const auth= {
|
|
49
|
-
...global_auth,
|
|
50
|
-
...route.auth || {}
|
|
51
|
-
}
|
|
52
|
-
_check_auth(ctx, auth, route.method)
|
|
53
|
-
|
|
54
|
-
const result= await route.callback(ctx, conn)
|
|
55
|
-
return result
|
|
56
|
-
}
|
|
57
|
-
|
|
58
|
-
if (route.method == 'POST') {
|
|
59
|
-
router.post(route.path, route_callback)
|
|
60
|
-
} else {
|
|
61
|
-
router.get(route.path, route_callback)
|
|
62
|
-
}
|
|
63
|
-
|
|
64
|
-
})
|
|
65
|
-
|
|
66
|
-
app.use(router.routes())
|
|
67
|
-
|
|
68
|
-
}
|
|
69
|
-
|
|
70
|
-
export {init_queries_router}
|