miolo 2.0.0-beta.1 → 2.0.0-beta.3
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.umd.js +1 -1
- package/dist/cli-react/miolo.cli-react.umd.js +1 -1
- package/dist/server/miolo.server.node.mjs +1 -1
- package/package.json +18 -18
- package/src/cli/catcher/index.mjs +75 -0
- package/src/cli/fetcher/fetcher.mjs +214 -0
- package/src/cli/fetcher/index.mjs +7 -0
- package/src/cli/fetcher/utils.mjs +51 -0
- package/src/cli/fetcher/v1.tar.gz +0 -0
- package/src/cli/index.mjs +30 -0
- package/src/cli/socket/index.mjs +6 -0
- package/src/cli-react/AppBrowser.jsx +14 -0
- package/src/cli-react/AppBrowser.mjs +14 -0
- package/src/cli-react/AppServer.jsx +17 -0
- package/src/cli-react/AppServer.mjs +16 -0
- package/src/cli-react/_jsx.tar.gz +0 -0
- package/src/cli-react/context/MioloContext.mjs +5 -0
- package/src/cli-react/context/MioloContextProvider.jsx +87 -0
- package/src/cli-react/context/MioloContextProvider.mjs +80 -0
- package/src/cli-react/context/useMioloContext.jsx +6 -0
- package/src/cli-react/context/useMioloContext.mjs +6 -0
- package/src/cli-react/context/withMioloContext.jsx +15 -0
- package/src/cli-react/context/withMioloContext.mjs +17 -0
- package/src/cli-react/index.mjs +7 -0
- package/src/cli-react/ssr/getSsrDataFromContext.mjs +33 -0
- package/src/cli-react/ssr/hooks.tar.gz +0 -0
- package/src/cli-react/ssr/useSsrDataOrReload.mjs +43 -0
- package/src/server/config/defaults.mjs +418 -0
- package/src/server/config/index.mjs +32 -0
- package/src/server/engines/cron/emails.mjs +10 -0
- package/src/server/engines/cron/index.mjs +153 -0
- package/src/server/engines/cron/init.mjs +53 -0
- package/src/server/engines/cron/ipsum.mjs +151 -0
- package/src/server/engines/cron/syscheck.mjs +56 -0
- package/src/server/engines/emailer/index.mjs +2 -0
- package/src/server/engines/emailer/queue.mjs +54 -0
- package/src/server/engines/emailer/transporter.mjs +149 -0
- package/src/server/engines/geoip/index.mjs +66 -0
- package/src/server/engines/http/index.mjs +79 -0
- package/src/server/engines/logger/index.mjs +313 -0
- package/src/server/engines/logger/logger_mail.mjs +89 -0
- package/src/server/engines/logger/reopenTransportOnHupSignal.mjs +57 -0
- package/src/server/engines/logger/verify.mjs +22 -0
- package/src/server/engines/parser/Parser.mjs +126 -0
- package/src/server/engines/parser/index.mjs +6 -0
- package/src/server/engines/socket/index.mjs +67 -0
- package/src/server/index.mjs +16 -0
- package/src/server/middleware/auth/basic.mjs +90 -0
- package/src/server/middleware/auth/credentials/index.mjs +151 -0
- package/src/server/middleware/auth/credentials/session/index.mjs +24 -0
- package/src/server/middleware/auth/credentials/session/store.mjs +59 -0
- package/src/server/middleware/auth/credentials/session/store_koa_redis.mjs +3 -0
- package/src/server/middleware/auth/custom.mjs +29 -0
- package/src/server/middleware/auth/guest.mjs +75 -0
- package/src/server/middleware/context/cache/index.mjs +61 -0
- package/src/server/middleware/context/cache/options.mjs +66 -0
- package/src/server/middleware/context/db.mjs +58 -0
- package/src/server/middleware/context/index.mjs +35 -0
- package/src/server/middleware/extra.mjs +12 -0
- package/src/server/middleware/http/body.mjs +31 -0
- package/src/server/middleware/http/catcher.mjs +81 -0
- package/src/server/middleware/http/custom_blacklist.mjs +16 -0
- package/src/server/middleware/http/headers.mjs +73 -0
- package/src/server/middleware/http/ratelimit.mjs +66 -0
- package/src/server/middleware/http/request.mjs +146 -0
- package/src/server/middleware/routes/catch_js_error.mjs +41 -0
- package/src/server/middleware/routes/robots.mjs +21 -0
- package/src/server/middleware/routes/router/crud/attachCrudRoutes.mjs +214 -0
- package/src/server/middleware/routes/router/crud/getCrudConfig.mjs +129 -0
- package/src/server/middleware/routes/router/defaults.mjs +29 -0
- package/src/server/middleware/routes/router/index.mjs +49 -0
- package/src/server/middleware/routes/router/queries/attachQueriesRoutes.mjs +102 -0
- package/src/server/middleware/routes/router/queries/getQueriesConfig.mjs +113 -0
- package/src/server/middleware/routes/router/utils.mjs +38 -0
- package/src/server/middleware/ssr/_old.tar.gz +0 -0
- package/src/server/middleware/ssr/context.mjs +21 -0
- package/src/server/middleware/ssr/fallbackIndex.mjs +29 -0
- package/src/server/middleware/ssr/html.mjs +64 -0
- package/src/server/middleware/ssr/loader.mjs +24 -0
- package/src/server/middleware/ssr/ssr_render.mjs +49 -0
- package/src/server/middleware/static/afialapis.ico +0 -0
- package/src/server/middleware/static/index.mjs +27 -0
- package/src/server/middleware/static/miolo.ico +0 -0
- package/src/server/middleware/vite/devserver.mjs +34 -0
- package/src/server/server-dev.mjs +41 -0
- package/src/server/server.mjs +135 -0
- package/src/server/static/img/afialapis.ico +0 -0
- package/src/server/static/img/miolo.ico +0 -0
- package/src/server/static/robots.txt +2 -0
- package/dist/cli/miolo.cli.iife.bundle.js +0 -968
- package/dist/cli/miolo.cli.iife.bundle.js.map +0 -1
- package/dist/cli/miolo.cli.iife.bundle.min.js +0 -13
- package/dist/cli/miolo.cli.iife.js +0 -968
- package/dist/cli/miolo.cli.iife.js.map +0 -1
- package/dist/cli/miolo.cli.iife.min.js +0 -13
- package/dist/cli/miolo.cli.min.mjs +0 -13
- package/dist/cli/miolo.cli.mjs +0 -485
- package/dist/cli/miolo.cli.mjs.map +0 -1
- package/dist/cli/miolo.cli.umd.bundle.js +0 -969
- package/dist/cli/miolo.cli.umd.bundle.js.map +0 -1
- package/dist/cli/miolo.cli.umd.bundle.min.js +0 -13
- package/dist/cli/miolo.cli.umd.min.js +0 -13
- package/dist/cli-react/miolo.cli-react.iife.bundle.js +0 -1232
- package/dist/cli-react/miolo.cli-react.iife.bundle.js.map +0 -1
- package/dist/cli-react/miolo.cli-react.iife.bundle.min.js +0 -13
- package/dist/cli-react/miolo.cli-react.iife.js +0 -1174
- package/dist/cli-react/miolo.cli-react.iife.js.map +0 -1
- package/dist/cli-react/miolo.cli-react.iife.min.js +0 -13
- package/dist/cli-react/miolo.cli-react.min.mjs +0 -13
- package/dist/cli-react/miolo.cli-react.mjs +0 -655
- package/dist/cli-react/miolo.cli-react.mjs.map +0 -1
- package/dist/cli-react/miolo.cli-react.umd.bundle.js +0 -1233
- package/dist/cli-react/miolo.cli-react.umd.bundle.js.map +0 -1
- package/dist/cli-react/miolo.cli-react.umd.bundle.min.js +0 -13
- package/dist/cli-react/miolo.cli-react.umd.min.js +0 -13
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
import React, { useState, useEffect, useCallback } from 'react'
|
|
2
|
+
import Context from './MioloContext.mjs'
|
|
3
|
+
import { miolo_client } from '../../cli/index.mjs'
|
|
4
|
+
import { useSsrDataOrReload } from '../ssr/useSsrDataOrReload.mjs'
|
|
5
|
+
|
|
6
|
+
const MioloContextProvider = ({ context, children }) => {
|
|
7
|
+
const [innerContext, setInnerContext] = useState(context)
|
|
8
|
+
const [mioloObj, setMioloObj] = useState(miolo_client(context))
|
|
9
|
+
|
|
10
|
+
useEffect(() => {
|
|
11
|
+
setInnerContext(context)
|
|
12
|
+
setMioloObj(miolo_client(context))
|
|
13
|
+
}, [context])
|
|
14
|
+
|
|
15
|
+
const login = useCallback(async (credentials) => {
|
|
16
|
+
const { fetcher } = mioloObj
|
|
17
|
+
const { config } = innerContext
|
|
18
|
+
|
|
19
|
+
const url = config.login_url || '/login'
|
|
20
|
+
const resp = await fetcher.login(url, credentials)
|
|
21
|
+
|
|
22
|
+
if (resp?.data) {
|
|
23
|
+
const nContext = {
|
|
24
|
+
...innerContext,
|
|
25
|
+
...resp?.data,
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
if (resp?.data?.authenticated) {
|
|
29
|
+
setInnerContext(nContext)
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
return resp?.data
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
return {}
|
|
36
|
+
}, [innerContext, mioloObj])
|
|
37
|
+
|
|
38
|
+
const logout = useCallback(async () => {
|
|
39
|
+
const { fetcher } = mioloObj
|
|
40
|
+
const { config } = innerContext
|
|
41
|
+
|
|
42
|
+
const url = config.logout_url || '/logout'
|
|
43
|
+
const _resp = await fetcher.logout(url)
|
|
44
|
+
// resp.redirected= true
|
|
45
|
+
|
|
46
|
+
const nContext = {
|
|
47
|
+
...innerContext,
|
|
48
|
+
user: undefined,
|
|
49
|
+
authenticated: false,
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
setInnerContext(nContext)
|
|
53
|
+
|
|
54
|
+
return {
|
|
55
|
+
user: undefined,
|
|
56
|
+
authenticated: false,
|
|
57
|
+
}
|
|
58
|
+
}, [innerContext, mioloObj])
|
|
59
|
+
|
|
60
|
+
const useSsrData = (name, defval, loader, modifier) => {
|
|
61
|
+
return useSsrDataOrReload(innerContext, mioloObj, name, defval, loader, modifier)
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
return React.createElement(
|
|
65
|
+
Context.Provider,
|
|
66
|
+
{
|
|
67
|
+
value: {
|
|
68
|
+
user: innerContext.user,
|
|
69
|
+
authenticated: innerContext.authenticated,
|
|
70
|
+
fetcher: mioloObj.fetcher,
|
|
71
|
+
login,
|
|
72
|
+
logout,
|
|
73
|
+
useSsrData,
|
|
74
|
+
},
|
|
75
|
+
},
|
|
76
|
+
children
|
|
77
|
+
)
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
export default MioloContextProvider
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import React, {useContext} from 'react'
|
|
2
|
+
import MioloContext from './MioloContext.mjs'
|
|
3
|
+
|
|
4
|
+
/* eslint react/display-name:0 */
|
|
5
|
+
const withMioloContext = (BaseComponent) => (props) => {
|
|
6
|
+
const context = useContext(MioloContext)
|
|
7
|
+
|
|
8
|
+
return (
|
|
9
|
+
<BaseComponent {...props}
|
|
10
|
+
{...context}/>
|
|
11
|
+
);
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
export default withMioloContext
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import React, { useContext } from 'react'
|
|
2
|
+
import MioloContext from './MioloContext.mjs'
|
|
3
|
+
|
|
4
|
+
/* eslint react/display-name:0 */
|
|
5
|
+
const withMioloContext = (BaseComponent) => (props) => {
|
|
6
|
+
const context = useContext(MioloContext)
|
|
7
|
+
|
|
8
|
+
return React.createElement(
|
|
9
|
+
BaseComponent,
|
|
10
|
+
{
|
|
11
|
+
...props,
|
|
12
|
+
...context,
|
|
13
|
+
}
|
|
14
|
+
)
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
export default withMioloContext
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import withMioloContext from './context/withMioloContext.jsx'
|
|
2
|
+
import useMioloContext from './context/useMioloContext.jsx'
|
|
3
|
+
|
|
4
|
+
import AppBrowser from './AppBrowser.jsx'
|
|
5
|
+
import AppServer from './AppServer.jsx'
|
|
6
|
+
|
|
7
|
+
export {withMioloContext, useMioloContext, AppBrowser, AppServer}
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
|
|
2
|
+
const _getDataFromWindow = (name) => {
|
|
3
|
+
try {
|
|
4
|
+
if (window != undefined) {
|
|
5
|
+
const ssr_data= window.__CONTEXT.ssr_data
|
|
6
|
+
|
|
7
|
+
if (ssr_data!=undefined) {
|
|
8
|
+
if (ssr_data[name]!=undefined) {
|
|
9
|
+
return ssr_data[name]
|
|
10
|
+
}
|
|
11
|
+
}
|
|
12
|
+
}
|
|
13
|
+
} catch(e) {}
|
|
14
|
+
|
|
15
|
+
return undefined
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
const getSsrDataFromContext = (context, name) => {
|
|
19
|
+
let data= undefined
|
|
20
|
+
|
|
21
|
+
if (context?.ssr_data != undefined && context?.ssr_data[name]!=undefined) {
|
|
22
|
+
data= context.ssr_data[name]
|
|
23
|
+
} else {
|
|
24
|
+
const wdata= _getDataFromWindow(name)
|
|
25
|
+
if (wdata != undefined) {
|
|
26
|
+
data= wdata
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
return data
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
export default getSsrDataFromContext
|
|
Binary file
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
import {useState, useCallback, useEffect} from 'react'
|
|
2
|
+
import getSsrDataFromContext from './getSsrDataFromContext.mjs'
|
|
3
|
+
|
|
4
|
+
const useSsrDataOrReload = (context, miolo, name, defval, loader, modifier) => {
|
|
5
|
+
|
|
6
|
+
const _maybeModify = useCallback((value) => {
|
|
7
|
+
return modifier==undefined ? value : modifier(value)
|
|
8
|
+
}, [modifier])
|
|
9
|
+
|
|
10
|
+
const ssrDataFromContext = getSsrDataFromContext(context, name)
|
|
11
|
+
const [ssrData, setSsrData] = useState(_maybeModify(
|
|
12
|
+
ssrDataFromContext != undefined
|
|
13
|
+
? ssrDataFromContext : defval))
|
|
14
|
+
const [needToRefresh, setNeedToRefresh] = useState(ssrDataFromContext == undefined)
|
|
15
|
+
|
|
16
|
+
const refreshSsrData = useCallback(() => {
|
|
17
|
+
if (loader == undefined) {
|
|
18
|
+
return
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
const {fetcher} = miolo
|
|
22
|
+
|
|
23
|
+
async function fetchData() {
|
|
24
|
+
let nSsrData = await loader(context, fetcher)
|
|
25
|
+
setSsrData(_maybeModify(nSsrData))
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
fetchData()
|
|
29
|
+
}, [context, miolo, loader, _maybeModify])
|
|
30
|
+
|
|
31
|
+
useEffect(() => {
|
|
32
|
+
try {
|
|
33
|
+
if (needToRefresh) {
|
|
34
|
+
setNeedToRefresh(false)
|
|
35
|
+
refreshSsrData()
|
|
36
|
+
}
|
|
37
|
+
} catch(e) {}
|
|
38
|
+
}, [needToRefresh, refreshSsrData])
|
|
39
|
+
|
|
40
|
+
return [ssrData, (data) => setSsrData(_maybeModify(data)), refreshSsrData]
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
export {useSsrDataOrReload}
|
|
@@ -0,0 +1,418 @@
|
|
|
1
|
+
const SESSION_MAX_AGE = 86400 * 10 * 1000
|
|
2
|
+
|
|
3
|
+
export default {
|
|
4
|
+
name: 'miolo',
|
|
5
|
+
http: {
|
|
6
|
+
port: 8001,
|
|
7
|
+
hostname: 'localhost',
|
|
8
|
+
|
|
9
|
+
catcher_url: '/sys/jserror',
|
|
10
|
+
|
|
11
|
+
static: {
|
|
12
|
+
favicon: '',
|
|
13
|
+
folders: {}
|
|
14
|
+
},
|
|
15
|
+
|
|
16
|
+
// cors can be:
|
|
17
|
+
// - false
|
|
18
|
+
// - simple (just assign Access-Control-Allow-Origin='*' and Access-Control-Expose-Headers='SourceMap,X-SourceMap'
|
|
19
|
+
// - true enable @koa/cors
|
|
20
|
+
// - {options} enable @koa/cors and use the custom options
|
|
21
|
+
//
|
|
22
|
+
cors: 'simple',
|
|
23
|
+
|
|
24
|
+
// proxy can be:
|
|
25
|
+
// - false
|
|
26
|
+
// - true enable koa-proxies and use default options
|
|
27
|
+
// - {options} enable koa-proxies and use the custom options
|
|
28
|
+
proxy: false,
|
|
29
|
+
|
|
30
|
+
ratelimit: {
|
|
31
|
+
/* eslint-disable no-unused-vars */
|
|
32
|
+
max: 1000,
|
|
33
|
+
duration: 60 * 1000, // miliseconds
|
|
34
|
+
errorMessage: 'Rate Limit reached',
|
|
35
|
+
//whitelist: (ctx) => false,
|
|
36
|
+
//blacklist: (ctx) => false,
|
|
37
|
+
whitelist_ips: [],
|
|
38
|
+
blacklist_ips: [],
|
|
39
|
+
ipsum_folder: '/var/ipsum' // https://github.com/stamparm/ipsum
|
|
40
|
+
},
|
|
41
|
+
|
|
42
|
+
request: {
|
|
43
|
+
lazy: 1, // seconds to consider lazy a request
|
|
44
|
+
slow: 2, // seconds to consider slow a request
|
|
45
|
+
onStart: undefined,
|
|
46
|
+
// (ctx, times) => { return begin_result}
|
|
47
|
+
onDone: undefined,
|
|
48
|
+
// (ctx, begin_result, times) => {},
|
|
49
|
+
geoip: {
|
|
50
|
+
enabled: false,
|
|
51
|
+
db: '/var/lib/GeoIP/GeoLite2-City.mmdb',
|
|
52
|
+
local_ips: [
|
|
53
|
+
'127.0.0.1'
|
|
54
|
+
]
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
},
|
|
59
|
+
session: {
|
|
60
|
+
salt: 'SUPER_SALTY_YES?',
|
|
61
|
+
secret: 'SUPER_SECRET_KEY_KERE',
|
|
62
|
+
options: {
|
|
63
|
+
/** (number || 'session') maxAge in ms (default is 1 days) */
|
|
64
|
+
/** 'session' will result in a cookie that expires when session/browser is closed */
|
|
65
|
+
/** Warning: If a session cookie is stolen, this cookie will never expire */
|
|
66
|
+
maxAge: SESSION_MAX_AGE,
|
|
67
|
+
|
|
68
|
+
/** (boolean) automatically commit headers (default true) */
|
|
69
|
+
//autoCommit: true,
|
|
70
|
+
|
|
71
|
+
/** (boolean) can overwrite or not (default true) */
|
|
72
|
+
//overwrite: true,
|
|
73
|
+
|
|
74
|
+
/** (boolean) httpOnly or not (default true) */
|
|
75
|
+
//httpOnly: true,
|
|
76
|
+
|
|
77
|
+
/** (boolean) signed or not (default true) */
|
|
78
|
+
//signed: true,
|
|
79
|
+
|
|
80
|
+
/** (boolean) Force a session identifier cookie to be set on every response. The expiration is reset to the original maxAge, resetting the expiration countdown. (default is false) */
|
|
81
|
+
//rolling: false,
|
|
82
|
+
|
|
83
|
+
/** (boolean) renew session when session is nearly expired, so we can always keep user logged in. (default is false)*/
|
|
84
|
+
//renew: false,
|
|
85
|
+
|
|
86
|
+
/** (boolean) secure cookie*/
|
|
87
|
+
/** You may want to set it as true in your Production environement,
|
|
88
|
+
* while false at DEV time.
|
|
89
|
+
*/
|
|
90
|
+
secure: true,
|
|
91
|
+
|
|
92
|
+
/** (string) session cookie sameSite options (default null, don't set it) */
|
|
93
|
+
sameSite: 'lax', // 'strict',
|
|
94
|
+
}
|
|
95
|
+
},
|
|
96
|
+
db: {
|
|
97
|
+
config: {
|
|
98
|
+
dialect: 'postgres',
|
|
99
|
+
host: 'localhost',
|
|
100
|
+
port: 5432,
|
|
101
|
+
database: 'miolo',
|
|
102
|
+
user: 'postgres',
|
|
103
|
+
password: 'postgres',
|
|
104
|
+
max: 5, // Maximum number of connection in pool
|
|
105
|
+
min: 0, // Minimum number of connection in pool
|
|
106
|
+
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,
|
|
107
|
+
},
|
|
108
|
+
options: {
|
|
109
|
+
tables: []
|
|
110
|
+
|
|
111
|
+
// cache:
|
|
112
|
+
// Refer to top level cache option
|
|
113
|
+
// cache: {...}
|
|
114
|
+
|
|
115
|
+
// log:
|
|
116
|
+
// We will pass, on the fly, miolo logger to calustra
|
|
117
|
+
// But specifying a level here, we can customize the level only for db/calustra actions
|
|
118
|
+
// log: 'silly',
|
|
119
|
+
}
|
|
120
|
+
},
|
|
121
|
+
routes: {
|
|
122
|
+
bodyField: undefined,
|
|
123
|
+
|
|
124
|
+
// auth: {
|
|
125
|
+
// require: false, // true / false / 'read-only'
|
|
126
|
+
// action: 'redirect', // 'error'
|
|
127
|
+
// redirect_url: '/',
|
|
128
|
+
// error_code: 401
|
|
129
|
+
// },
|
|
130
|
+
// before: async (ctx) => {return bool} // If bool false, query callback not run
|
|
131
|
+
// after : async (ctx, result) => {return modified_result}
|
|
132
|
+
|
|
133
|
+
crud: [{
|
|
134
|
+
prefix: '',
|
|
135
|
+
routes: [/*
|
|
136
|
+
name: '',
|
|
137
|
+
url: '/../..', // default to 'name'
|
|
138
|
+
mode: 'r/w/rw',
|
|
139
|
+
bodyField: '',
|
|
140
|
+
|
|
141
|
+
useUserFields: {
|
|
142
|
+
use: false,
|
|
143
|
+
fieldNames: {
|
|
144
|
+
created_by: 'created_by',
|
|
145
|
+
last_update_by: 'last_update_by'
|
|
146
|
+
}
|
|
147
|
+
}
|
|
148
|
+
auth: ...,
|
|
149
|
+
before: ...,
|
|
150
|
+
after : ...
|
|
151
|
+
*/],
|
|
152
|
+
}],
|
|
153
|
+
queries: [/*
|
|
154
|
+
{
|
|
155
|
+
prefix: '',
|
|
156
|
+
auth: ...,
|
|
157
|
+
before: ...,
|
|
158
|
+
after : ...
|
|
159
|
+
|
|
160
|
+
routes: [
|
|
161
|
+
{
|
|
162
|
+
url: '/../..',
|
|
163
|
+
method: 'GET/POST',
|
|
164
|
+
callback: async (ctx) => { ctx.body = result } ,
|
|
165
|
+
// or
|
|
166
|
+
callback_fn: async (miolo, params) => { return result } ,
|
|
167
|
+
auth: ...,
|
|
168
|
+
before: ...,
|
|
169
|
+
after : ...
|
|
170
|
+
},
|
|
171
|
+
],
|
|
172
|
+
},
|
|
173
|
+
*/],
|
|
174
|
+
},
|
|
175
|
+
log: {
|
|
176
|
+
level: 'debug',
|
|
177
|
+
format: {
|
|
178
|
+
locale: 'en-GB'
|
|
179
|
+
},
|
|
180
|
+
console: {
|
|
181
|
+
enabled: true,
|
|
182
|
+
},
|
|
183
|
+
file: {
|
|
184
|
+
enabled: true,
|
|
185
|
+
|
|
186
|
+
filename: '/var/log/afialapis/%MIOLO%.log',
|
|
187
|
+
|
|
188
|
+
//frequency: undefined,
|
|
189
|
+
//datePattern: 'YYYY-MM-DD',
|
|
190
|
+
zippedArchive: true,
|
|
191
|
+
|
|
192
|
+
maxsize: 1024 * 1024 * 20,
|
|
193
|
+
maxFiles: 20,
|
|
194
|
+
|
|
195
|
+
//maxSize: '20m',
|
|
196
|
+
///maxFiles: '10d',
|
|
197
|
+
|
|
198
|
+
//filename: '/var/log/afialapis/%MIOLO%.%DATE%.log',
|
|
199
|
+
//auditFile: '/var/log/afialapis/%MIOLO%.audit.json',
|
|
200
|
+
//createSymlink: true,
|
|
201
|
+
//symlinkName: '%MIOLO%.log'
|
|
202
|
+
|
|
203
|
+
hup_patch: false
|
|
204
|
+
},
|
|
205
|
+
mail: {
|
|
206
|
+
enabled: false,
|
|
207
|
+
level: 'warn',
|
|
208
|
+
name: 'miolo',
|
|
209
|
+
from: 'miolo@mail.com',
|
|
210
|
+
to: 'errors@mail.com'
|
|
211
|
+
}
|
|
212
|
+
},
|
|
213
|
+
mail: {
|
|
214
|
+
silent: true,
|
|
215
|
+
options: {
|
|
216
|
+
//
|
|
217
|
+
// General options
|
|
218
|
+
//
|
|
219
|
+
// port – is the port to connect to (defaults to 587 is secure is false or 465 if true)
|
|
220
|
+
port: 25,
|
|
221
|
+
// host – is the hostname or IP address to connect to (defaults to ‘localhost’)
|
|
222
|
+
host: 'mail.com',
|
|
223
|
+
// auth – defines authentication data
|
|
224
|
+
// If authentication data is not present, the connection is considered authenticated from the start.
|
|
225
|
+
// Otherwise you would need to provide the authentication options object.
|
|
226
|
+
// - type indicates the authetication type, defaults to ‘login’, other option is ‘oauth2’
|
|
227
|
+
// - user is the username
|
|
228
|
+
// - pass is the password for the user if normal login is used
|
|
229
|
+
// authMethod – defines preferred authentication method, defaults to ‘PLAIN’
|
|
230
|
+
authMethod: 'PLAIN',
|
|
231
|
+
//
|
|
232
|
+
// TLS options
|
|
233
|
+
//
|
|
234
|
+
// secure – if true the connection will use TLS when connecting to server.
|
|
235
|
+
// If false (the default) then TLS is used if server supports the STARTTLS extension.
|
|
236
|
+
// In most cases set this value to true if you are connecting to port 465. For port 587 or 25 keep it false
|
|
237
|
+
// ** Setting secure to false does not mean that you would not use an encrypted connection. Most SMTP servers allow
|
|
238
|
+
// connection upgrade via STARTTLS command but to use this you have to connect using plaintext first
|
|
239
|
+
secure: false,
|
|
240
|
+
// tls – defines additional node.js TLSSocket options to be passed to the socket constructor, eg. {rejectUnauthorized: true}.
|
|
241
|
+
tls: {
|
|
242
|
+
// do not fail on invalid certs
|
|
243
|
+
rejectUnauthorized: false
|
|
244
|
+
} ,
|
|
245
|
+
// ignoreTLS – if this is true and secure is false then TLS is not used even if the server supports STARTTLS extension
|
|
246
|
+
// ** ignoreTLS: false,
|
|
247
|
+
// requireTLS – if this is true and secure is false then Nodemailer tries to use STARTTLS even
|
|
248
|
+
// if the server does not advertise support for it. If the connection can not be encrypted then message is not sent
|
|
249
|
+
// ** requireTLS: true,
|
|
250
|
+
//
|
|
251
|
+
// Connection options
|
|
252
|
+
//
|
|
253
|
+
// name – optional hostname of the client, used for identifying to the server, defaults to hostname of the machine
|
|
254
|
+
// ** name: ,
|
|
255
|
+
// localAddress – is the local interface to bind to for network connections
|
|
256
|
+
// ** localAddress: ,
|
|
257
|
+
// connectionTimeout – how many milliseconds to wait for the connection to establish
|
|
258
|
+
// ** connectionTimeout: ,
|
|
259
|
+
// greetingTimeout – how many milliseconds to wait for the greeting after connection is established
|
|
260
|
+
// ** greetingTimeout: ,
|
|
261
|
+
// socketTimeout – how many milliseconds of inactivity to allow
|
|
262
|
+
// ** socketTimeout: ,
|
|
263
|
+
//
|
|
264
|
+
// Debug options
|
|
265
|
+
//
|
|
266
|
+
// logger – optional bunyan compatible logger instance. If set to true then logs to console.
|
|
267
|
+
// If value is not set or is false then nothing is logged
|
|
268
|
+
logger: false,
|
|
269
|
+
// debug – if set to true, then logs SMTP traffic, otherwise logs only transaction events
|
|
270
|
+
debug: false,
|
|
271
|
+
//
|
|
272
|
+
// Security options
|
|
273
|
+
//
|
|
274
|
+
// disableFileAccess – if true, then does not allow to use files as content.
|
|
275
|
+
// Use it when you want to use JSON data from untrusted source as the email.
|
|
276
|
+
// If an attachment or message node tries to fetch something from a file the sending returns an error
|
|
277
|
+
////disableFileAccess: ,
|
|
278
|
+
// disableUrlAccess – if true, then does not allow to use Urls as content
|
|
279
|
+
// ** disableUrlAccess: ,
|
|
280
|
+
|
|
281
|
+
//
|
|
282
|
+
// Pooling options
|
|
283
|
+
//
|
|
284
|
+
// pool – see Pooled SMTP for details about connection pooling : https://nodemailer.com/smtp/pooled/
|
|
285
|
+
//
|
|
286
|
+
// Proxy options
|
|
287
|
+
//
|
|
288
|
+
// proxy – all SMTP based transports allow to use proxies for making TCP connections to servers.
|
|
289
|
+
// Read about proxy support in Nodemailer from here: https://nodemailer.com/smtp/proxies/
|
|
290
|
+
},
|
|
291
|
+
defaults: {
|
|
292
|
+
name: 'miolo',
|
|
293
|
+
from: 'miolo@mail.com',
|
|
294
|
+
to: 'errors@mail.com'
|
|
295
|
+
}
|
|
296
|
+
},
|
|
297
|
+
auth: {
|
|
298
|
+
//basic: {
|
|
299
|
+
// auth_user: async (username, password) => { return {id: 1} },
|
|
300
|
+
// realm: '',
|
|
301
|
+
// paths: [],
|
|
302
|
+
//},
|
|
303
|
+
//credentials: {
|
|
304
|
+
// get_user_id: (user, done, miolo) => done(null, user.id), // default
|
|
305
|
+
// find_user_by_id: (id, done, miolo) => done(null, {id: 1}), // ok=> done(null, user) err=> done(error, null)
|
|
306
|
+
// local_auth_user: (username, password, done, miolo) => done(null, {id: 1})
|
|
307
|
+
// // auth=> done(null, user) noauth=> done(null, false, {message: ''}) err=> done(error, null)
|
|
308
|
+
// url_login : '/login',
|
|
309
|
+
// url_logout: '/logout',
|
|
310
|
+
// url_login_redirect: undefined
|
|
311
|
+
// url_logout_redirect: '/'
|
|
312
|
+
//}
|
|
313
|
+
//guest: {
|
|
314
|
+
// make_guest_token: undefined // (session) => ''
|
|
315
|
+
//},
|
|
316
|
+
//custom: callback,
|
|
317
|
+
// here callback receives (app)
|
|
318
|
+
// and returns:
|
|
319
|
+
// - a middleware function
|
|
320
|
+
// or
|
|
321
|
+
// - an array like [{
|
|
322
|
+
// method: 'GET' // POST,...
|
|
323
|
+
// url: '/aa/bb',
|
|
324
|
+
// callback: a middleware function
|
|
325
|
+
// }, ...]
|
|
326
|
+
},
|
|
327
|
+
middlewares: [
|
|
328
|
+
// async (ctx, next) => {}
|
|
329
|
+
// Remember to call `await next()`
|
|
330
|
+
],
|
|
331
|
+
cron: [
|
|
332
|
+
// {
|
|
333
|
+
// name,
|
|
334
|
+
// cronTime,
|
|
335
|
+
// onTick(miolo, onComplete),
|
|
336
|
+
// Notice that if task runs too fast, you may see that
|
|
337
|
+
// onTick is actually never run, but onComplete is.
|
|
338
|
+
// Consider passing a higher interval on cronTime
|
|
339
|
+
// onComplete(miolo),
|
|
340
|
+
// timezone, context, runOnInit, utcOffset, unrefTimeout
|
|
341
|
+
// }
|
|
342
|
+
// check https://github.com/kelektiv/node-cron#readme
|
|
343
|
+
//
|
|
344
|
+
// https://crontab.guru/
|
|
345
|
+
],
|
|
346
|
+
|
|
347
|
+
cache: {
|
|
348
|
+
// Default options passed to cacheiro for
|
|
349
|
+
// every other cache
|
|
350
|
+
default: {
|
|
351
|
+
type: 'combined',
|
|
352
|
+
redis: {
|
|
353
|
+
host: '127.0.0.1',
|
|
354
|
+
port: 6379
|
|
355
|
+
},
|
|
356
|
+
version: 1,
|
|
357
|
+
clean: false,
|
|
358
|
+
},
|
|
359
|
+
|
|
360
|
+
// specific cache options for calustra
|
|
361
|
+
calustra: {
|
|
362
|
+
namespace: 'miolo-calustra',
|
|
363
|
+
ttl: 86400*1000,
|
|
364
|
+
},
|
|
365
|
+
|
|
366
|
+
// specific cache options for koa-session
|
|
367
|
+
session: {
|
|
368
|
+
namespace: 'miolo-session',
|
|
369
|
+
ttl: SESSION_MAX_AGE,
|
|
370
|
+
},
|
|
371
|
+
|
|
372
|
+
// custom cache instances
|
|
373
|
+
// will be inited by miolo, and available through ctx.miolo.cache.get_cache('name')
|
|
374
|
+
custom: {
|
|
375
|
+
// <name>: {options}
|
|
376
|
+
}
|
|
377
|
+
|
|
378
|
+
|
|
379
|
+
},
|
|
380
|
+
|
|
381
|
+
socket: {
|
|
382
|
+
enabled: false,
|
|
383
|
+
cli: {
|
|
384
|
+
/**
|
|
385
|
+
domain: '',
|
|
386
|
+
options: {}
|
|
387
|
+
*/
|
|
388
|
+
}
|
|
389
|
+
/*
|
|
390
|
+
connection: (socket) => {},
|
|
391
|
+
new_namespace: (namespace) => {},
|
|
392
|
+
namespaces: [{
|
|
393
|
+
name,
|
|
394
|
+
listener: (data) => {}
|
|
395
|
+
}]
|
|
396
|
+
*/
|
|
397
|
+
},
|
|
398
|
+
|
|
399
|
+
// vite: false,
|
|
400
|
+
vite: {
|
|
401
|
+
base: '/',
|
|
402
|
+
root: '',
|
|
403
|
+
watch: {
|
|
404
|
+
// During tests we edit the files too fast and sometimes chokidar
|
|
405
|
+
// misses change events, so enforce polling for consistency
|
|
406
|
+
usePolling: true,
|
|
407
|
+
interval: 100,
|
|
408
|
+
},
|
|
409
|
+
},
|
|
410
|
+
|
|
411
|
+
ssr: {
|
|
412
|
+
client: 'cli/index.jsx',
|
|
413
|
+
server: 'server/index.jsx',
|
|
414
|
+
// html: '',
|
|
415
|
+
// loader: async (ctx) => {}
|
|
416
|
+
},
|
|
417
|
+
};
|
|
418
|
+
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import merge from 'deepmerge'
|
|
2
|
+
import base_config from './defaults.mjs'
|
|
3
|
+
|
|
4
|
+
function _get_auth_type(config) {
|
|
5
|
+
if (config?.auth?.basic) {
|
|
6
|
+
return 'basic'
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
if (config?.auth?.credentials) {
|
|
10
|
+
return 'credentials'
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
if (config?.auth?.custom) {
|
|
14
|
+
return 'custom'
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
return 'guest'
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
|
|
21
|
+
function init_config(config) {
|
|
22
|
+
const all_config= merge(base_config, config)
|
|
23
|
+
|
|
24
|
+
all_config.auth_type = _get_auth_type(config)
|
|
25
|
+
all_config.use_catcher = all_config?.http?.catcher_url ? true : false
|
|
26
|
+
|
|
27
|
+
return all_config
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
export {
|
|
31
|
+
init_config
|
|
32
|
+
}
|