miolo 2.1.0-beta.1 → 3.0.0-beta.2
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/bin/.env +107 -0
- package/bin/build-client.mjs +12 -11
- package/bin/build-server.mjs +7 -17
- package/bin/dev.mjs +10 -7
- package/bin/dev_start.mjs +11 -0
- package/bin/env.mjs +39 -0
- package/bin/index.mjs +21 -15
- package/bin/prod_start.mjs +9 -0
- package/bin/restart.mjs +0 -2
- package/bin/start.mjs +2 -12
- package/bin/stop.mjs +1 -4
- package/bin/util.mjs +11 -11
- package/package.json +16 -39
- package/src/{server/config → config}/defaults.mjs +107 -69
- package/src/{server/middleware → middleware}/ssr/html.mjs +20 -3
- package/src/{server/middleware → middleware}/ssr/ssr_render.mjs +2 -2
- package/src/{server/middleware → middleware}/vite/devserver.mjs +6 -6
- package/src/{server/server-cron.mjs → server-cron.mjs} +0 -2
- package/src/{server/server-dev.mjs → server-dev.mjs} +2 -2
- package/src/{server/server.mjs → server.mjs} +1 -3
- package/README.md +0 -69
- package/dist/cli/miolo.cli.mjs +0 -492
- package/dist/cli/miolo.cli.mjs.map +0 -1
- package/dist/cli/miolo.cli.umd.js +0 -749
- package/dist/cli/miolo.cli.umd.js.map +0 -1
- package/dist/cli-react/miolo.cli-react.mjs +0 -672
- package/dist/cli-react/miolo.cli-react.mjs.map +0 -1
- package/dist/cli-react/miolo.cli-react.umd.js +0 -959
- package/dist/cli-react/miolo.cli-react.umd.js.map +0 -1
- package/dist/server/miolo.server.node.mjs +0 -8050
- 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/logo/miolo_logo.png +0 -0
- package/logo/miolo_name.png +0 -0
- package/logo/miolo_sm.png +0 -0
- package/src/cli/catcher/index.mjs +0 -75
- package/src/cli/fetcher/fetcher.mjs +0 -214
- package/src/cli/fetcher/index.mjs +0 -7
- package/src/cli/fetcher/utils.mjs +0 -59
- package/src/cli/index.mjs +0 -30
- package/src/cli/socket/index.mjs +0 -6
- package/src/cli-react/AppBrowser.jsx +0 -14
- package/src/cli-react/AppServer.jsx +0 -17
- package/src/cli-react/context/MioloContext.mjs +0 -5
- package/src/cli-react/context/MioloContextProvider.jsx +0 -95
- package/src/cli-react/context/useMioloContext.jsx +0 -6
- package/src/cli-react/context/withMioloContext.jsx +0 -15
- package/src/cli-react/index.mjs +0 -7
- package/src/cli-react/ssr/getSsrDataFromContext.mjs +0 -33
- package/src/cli-react/ssr/useSsrDataOrReload.mjs +0 -43
- package/src/server/static/img/afialapis.ico +0 -0
- package/src/server/static/img/miolo.ico +0 -0
- package/src/server/static/robots.txt +0 -2
- /package/src/{server/config → config}/index.mjs +0 -0
- /package/src/{server/engines → engines}/cron/emails.mjs +0 -0
- /package/src/{server/engines → engines}/cron/index.mjs +0 -0
- /package/src/{server/engines → engines}/cron/init.mjs +0 -0
- /package/src/{server/engines → engines}/cron/ipsum.mjs +0 -0
- /package/src/{server/engines → engines}/cron/syscheck.mjs +0 -0
- /package/src/{server/engines → engines}/emailer/index.mjs +0 -0
- /package/src/{server/engines → engines}/emailer/queue.mjs +0 -0
- /package/src/{server/engines → engines}/emailer/transporter.mjs +0 -0
- /package/src/{server/engines → engines}/geoip/index.mjs +0 -0
- /package/src/{server/engines → engines}/http/index.mjs +0 -0
- /package/src/{server/engines → engines}/logger/index.mjs +0 -0
- /package/src/{server/engines → engines}/logger/logger_mail.mjs +0 -0
- /package/src/{server/engines → engines}/logger/reopenTransportOnHupSignal.mjs +0 -0
- /package/src/{server/engines → engines}/logger/verify.mjs +0 -0
- /package/src/{server/engines → engines}/parser/Parser.mjs +0 -0
- /package/src/{server/engines → engines}/parser/index.mjs +0 -0
- /package/src/{server/engines → engines}/socket/index.mjs +0 -0
- /package/src/{server/index.mjs → index.mjs} +0 -0
- /package/src/{server/middleware → middleware}/auth/basic.mjs +0 -0
- /package/src/{server/middleware → middleware}/auth/credentials/index.mjs +0 -0
- /package/src/{server/middleware → middleware}/auth/credentials/session/index.mjs +0 -0
- /package/src/{server/middleware → middleware}/auth/credentials/session/store.mjs +0 -0
- /package/src/{server/middleware → middleware}/auth/credentials/session/store_koa_redis.mjs +0 -0
- /package/src/{server/middleware → middleware}/auth/custom.mjs +0 -0
- /package/src/{server/middleware → middleware}/auth/guest.mjs +0 -0
- /package/src/{server/middleware → middleware}/context/cache/index.mjs +0 -0
- /package/src/{server/middleware → middleware}/context/cache/options.mjs +0 -0
- /package/src/{server/middleware → middleware}/context/db.mjs +0 -0
- /package/src/{server/middleware → middleware}/context/index.mjs +0 -0
- /package/src/{server/middleware → middleware}/extra.mjs +0 -0
- /package/src/{server/middleware → middleware}/http/body.mjs +0 -0
- /package/src/{server/middleware → middleware}/http/catcher.mjs +0 -0
- /package/src/{server/middleware → middleware}/http/custom_blacklist.mjs +0 -0
- /package/src/{server/middleware → middleware}/http/headers.mjs +0 -0
- /package/src/{server/middleware → middleware}/http/ratelimit.mjs +0 -0
- /package/src/{server/middleware → middleware}/http/request.mjs +0 -0
- /package/src/{server/middleware → middleware}/routes/catch_js_error.mjs +0 -0
- /package/src/{server/middleware → middleware}/routes/robots.mjs +0 -0
- /package/src/{server/middleware → middleware}/routes/router/crud/attachCrudRoutes.mjs +0 -0
- /package/src/{server/middleware → middleware}/routes/router/crud/getCrudConfig.mjs +0 -0
- /package/src/{server/middleware → middleware}/routes/router/defaults.mjs +0 -0
- /package/src/{server/middleware → middleware}/routes/router/index.mjs +0 -0
- /package/src/{server/middleware → middleware}/routes/router/queries/attachQueriesRoutes.mjs +0 -0
- /package/src/{server/middleware → middleware}/routes/router/queries/getQueriesConfig.mjs +0 -0
- /package/src/{server/middleware → middleware}/routes/router/utils.mjs +0 -0
- /package/src/{server/middleware → middleware}/ssr/context.mjs +0 -0
- /package/src/{server/middleware → middleware}/ssr/fallbackIndex.mjs +0 -0
- /package/src/{server/middleware → middleware}/ssr/loader.mjs +0 -0
- /package/{dist/static/img → src/middleware/static}/afialapis.ico +0 -0
- /package/src/{server/middleware → middleware}/static/index.mjs +0 -0
- /package/{dist/static/img → src/middleware/static}/miolo.ico +0 -0
- /package/src/{server/middleware → middleware}/vite/watcher.mjs +0 -0
- /package/src/{server/middleware/static → static/img}/afialapis.ico +0 -0
- /package/src/{server/middleware/static → static/img}/miolo.ico +0 -0
- /package/{dist → src}/static/robots.txt +0 -0
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import path from 'path'
|
|
1
2
|
const SESSION_MAX_AGE = 86400 * 10 * 1000
|
|
2
3
|
|
|
3
4
|
|
|
@@ -9,10 +10,10 @@ const SESSION_MAX_AGE = 86400 * 10 * 1000
|
|
|
9
10
|
|
|
10
11
|
|
|
11
12
|
export default {
|
|
12
|
-
name:
|
|
13
|
+
name: process.env.MIOLO_NAME,
|
|
13
14
|
http: {
|
|
14
|
-
port: 8001,
|
|
15
|
-
hostname: 'localhost',
|
|
15
|
+
port: process.env?.MIOLO_PORT || 8001,
|
|
16
|
+
hostname: process.env?.MIOLO_HOSTNAME || 'localhost',
|
|
16
17
|
|
|
17
18
|
catcher_url: '/sys/jserror',
|
|
18
19
|
|
|
@@ -27,37 +28,41 @@ export default {
|
|
|
27
28
|
// - true enable @koa/cors
|
|
28
29
|
// - {options} enable @koa/cors and use the custom options
|
|
29
30
|
//
|
|
30
|
-
cors: '
|
|
31
|
+
cors: process.env.MIOLO_HTTP_CORS==='true'
|
|
32
|
+
? true
|
|
33
|
+
: process.env.MIOLO_HTTP_CORS==='simple'
|
|
34
|
+
? 'simple'
|
|
35
|
+
: false,
|
|
31
36
|
|
|
32
37
|
// proxy can be:
|
|
33
38
|
// - false
|
|
34
39
|
// - true enable koa-proxies and use default options
|
|
35
40
|
// - {options} enable koa-proxies and use the custom options
|
|
36
|
-
proxy:
|
|
41
|
+
proxy: process.env.MIOLO_HTTP_PROXY==='true',
|
|
37
42
|
|
|
38
43
|
ratelimit: {
|
|
39
44
|
/* eslint-disable no-unused-vars */
|
|
40
|
-
max: 1000,
|
|
41
|
-
duration: 60 * 1000, // miliseconds
|
|
45
|
+
max: parseInt(process.env.MIOLO_RATELIMIT_MAX || 1000),
|
|
46
|
+
duration: parseInt(process.env.MIOLO_RATELIMIT_DURATION || 60 * 1000), // miliseconds
|
|
42
47
|
errorMessage: 'Rate Limit reached',
|
|
43
48
|
//whitelist: (ctx) => false,
|
|
44
49
|
//blacklist: (ctx) => false,
|
|
45
|
-
whitelist_ips: [],
|
|
46
|
-
blacklist_ips: [],
|
|
50
|
+
whitelist_ips: process.env.MIOLO_RATELIMIT_WHITELIST_IPS?.split(',') || [],
|
|
51
|
+
blacklist_ips: process.env.MIOLO_RATELIMIT_BLACKLIST_IPS?.split(',') || [],
|
|
47
52
|
ipsum_folder: '/var/ipsum' // https://github.com/stamparm/ipsum
|
|
48
53
|
},
|
|
49
54
|
|
|
50
55
|
request: {
|
|
51
|
-
lazy: 1, // seconds to consider lazy a request
|
|
52
|
-
slow: 2, // seconds to consider slow a request
|
|
56
|
+
lazy: parseInt(process.env.MIOLO_REQUEST_LAZY || 1), // seconds to consider lazy a request
|
|
57
|
+
slow: parseInt(process.env.MIOLO_REQUEST_SLOW || 2), // seconds to consider slow a request
|
|
53
58
|
onStart: undefined,
|
|
54
59
|
// (ctx, times) => { return begin_result}
|
|
55
60
|
onDone: undefined,
|
|
56
61
|
// (ctx, begin_result, times) => {},
|
|
57
62
|
geoip: {
|
|
58
|
-
enabled:
|
|
59
|
-
db:
|
|
60
|
-
local_ips: [
|
|
63
|
+
enabled: process.env.MIOLO_GEOIP_ENABLED==='true',
|
|
64
|
+
db: process.env.MIOLO_GEOIP_DB,
|
|
65
|
+
local_ips: process.env.MIOLO_GEOIP_LOCAL_IPS?.split(',') || [
|
|
61
66
|
'127.0.0.1'
|
|
62
67
|
]
|
|
63
68
|
}
|
|
@@ -65,13 +70,13 @@ export default {
|
|
|
65
70
|
|
|
66
71
|
},
|
|
67
72
|
session: {
|
|
68
|
-
salt: 'SUPER_SALTY_YES?',
|
|
69
|
-
secret: 'SUPER_SECRET_KEY_KERE',
|
|
73
|
+
salt: process.env.MIOLO_SESSION_SALT || 'SUPER_SALTY_YES?',
|
|
74
|
+
secret: process.env.MIOLO_SESSION_SECRET || 'SUPER_SECRET_KEY_KERE',
|
|
70
75
|
options: {
|
|
71
76
|
/** (number || 'session') maxAge in ms (default is 1 days) */
|
|
72
77
|
/** 'session' will result in a cookie that expires when session/browser is closed */
|
|
73
78
|
/** Warning: If a session cookie is stolen, this cookie will never expire */
|
|
74
|
-
maxAge: SESSION_MAX_AGE,
|
|
79
|
+
maxAge: parseInt(process.env.MIOLO_SESSION_MAX_AGE || SESSION_MAX_AGE),
|
|
75
80
|
|
|
76
81
|
/** (boolean) automatically commit headers (default true) */
|
|
77
82
|
//autoCommit: true,
|
|
@@ -95,7 +100,7 @@ export default {
|
|
|
95
100
|
/** You may want to set it as true in your Production environement,
|
|
96
101
|
* while false at DEV time.
|
|
97
102
|
*/
|
|
98
|
-
secure: true,
|
|
103
|
+
secure: process.env?.MIOLO_SESSION_SECURE === 'true',
|
|
99
104
|
|
|
100
105
|
/** (string) session cookie sameSite options (default null, don't set it) */
|
|
101
106
|
sameSite: 'lax', // 'strict',
|
|
@@ -103,15 +108,20 @@ export default {
|
|
|
103
108
|
},
|
|
104
109
|
db: {
|
|
105
110
|
config: {
|
|
106
|
-
dialect:
|
|
107
|
-
host:
|
|
108
|
-
port:
|
|
109
|
-
database:
|
|
110
|
-
user:
|
|
111
|
-
password:
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
111
|
+
dialect: process.env.MIOLO_DB_DIALECT,
|
|
112
|
+
host: process.env.MIOLO_DB_HOST,
|
|
113
|
+
port: process.env.MIOLO_DB_PORT,
|
|
114
|
+
database: process.env.MIOLO_DB_DATABASE,
|
|
115
|
+
user: process.env.MIOLO_DB_USER,
|
|
116
|
+
password: process.env.MIOLO_DB_PASSWORD,
|
|
117
|
+
// Maximum number of connection in pool
|
|
118
|
+
max: parseInt(process.env.MIOLO_DB_POOL_MAX),
|
|
119
|
+
// Minimum number of connection in pool
|
|
120
|
+
min: parseInt(process.env.MIOLO_DB_POOL_MIN),
|
|
121
|
+
// The maximum time, in milliseconds, that a connection can be idle before being released.
|
|
122
|
+
// Use with combination of evict for proper working,
|
|
123
|
+
// for more details read https://github.com/coopernurse/node-pool/issues/178#issuecomment-327110870,
|
|
124
|
+
idleTimeoutMillis: parseInt(process.env.MIOLO_DB_POOL_IDLE_TIMEOUT_MS),
|
|
115
125
|
},
|
|
116
126
|
options: {
|
|
117
127
|
tables: []
|
|
@@ -181,17 +191,18 @@ export default {
|
|
|
181
191
|
*/],
|
|
182
192
|
},
|
|
183
193
|
log: {
|
|
184
|
-
level: 'debug',
|
|
194
|
+
level: process.env.MIOLO_LOG_LEVEL || 'debug',
|
|
185
195
|
format: {
|
|
186
196
|
locale: 'en-GB'
|
|
187
197
|
},
|
|
188
198
|
console: {
|
|
189
|
-
enabled: true,
|
|
199
|
+
enabled: process.env.MIOLO_LOG_CONSOLE_ENABLED === 'true',
|
|
200
|
+
level: process.env.MIOLO_LOG_CONSOLE_LEVEL || process.env.MIOLO_LOG_LEVEL || 'debug',
|
|
190
201
|
},
|
|
191
202
|
file: {
|
|
192
|
-
enabled: true,
|
|
193
|
-
|
|
194
|
-
filename: '/var/log/afialapis/%MIOLO%.log',
|
|
203
|
+
enabled: process.env.MIOLO_LOG_FILE_ENABLED === 'true',
|
|
204
|
+
level: process.env.MIOLO_LOG_FILE_LEVEL || process.env.MIOLO_LOG_LEVEL || 'debug',
|
|
205
|
+
filename: process.env.MIOLO_LOG_FILE_PATH || '/var/log/afialapis/%MIOLO%.log',
|
|
195
206
|
|
|
196
207
|
//frequency: undefined,
|
|
197
208
|
//datePattern: 'YYYY-MM-DD',
|
|
@@ -211,23 +222,25 @@ export default {
|
|
|
211
222
|
hup_patch: false
|
|
212
223
|
},
|
|
213
224
|
mail: {
|
|
214
|
-
enabled:
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
225
|
+
enabled: process.env.MIOLO_LOG_MAIL_ENABLED
|
|
226
|
+
? process.env.MIOLO_LOG_MAIL_ENABLED === 'true'
|
|
227
|
+
: false,
|
|
228
|
+
level: process.env.MIOLO_LOG_MAIL_LEVEL || process.env.MIOLO_LOG_LEVEL || 'warn',
|
|
229
|
+
name: process.env.MIOLO_NAME || 'miolo',
|
|
230
|
+
from: process.env.MIOLO_LOG_MAIL_FROM || 'noreply@mail.com',
|
|
231
|
+
to: process.env.MIOLO_LOG_MAIL_TO || 'noreply@mail.com'
|
|
219
232
|
}
|
|
220
233
|
},
|
|
221
234
|
mail: {
|
|
222
|
-
silent: true,
|
|
235
|
+
silent: process.env.MIOLO_MAILER_SILENT === 'true',
|
|
223
236
|
options: {
|
|
224
237
|
//
|
|
225
238
|
// General options
|
|
226
239
|
//
|
|
227
240
|
// port – is the port to connect to (defaults to 587 is secure is false or 465 if true)
|
|
228
|
-
port: 25,
|
|
241
|
+
port: parseInt(process.env.MIOLO_MAILER_PORT || 25),
|
|
229
242
|
// host – is the hostname or IP address to connect to (defaults to ‘localhost’)
|
|
230
|
-
host: 'mail.com',
|
|
243
|
+
host: process.env.MIOLO_MAILER_HOST || 'mail.com',
|
|
231
244
|
// auth – defines authentication data
|
|
232
245
|
// If authentication data is not present, the connection is considered authenticated from the start.
|
|
233
246
|
// Otherwise you would need to provide the authentication options object.
|
|
@@ -235,7 +248,20 @@ export default {
|
|
|
235
248
|
// - user is the username
|
|
236
249
|
// - pass is the password for the user if normal login is used
|
|
237
250
|
// authMethod – defines preferred authentication method, defaults to ‘PLAIN’
|
|
238
|
-
authMethod: 'PLAIN',
|
|
251
|
+
authMethod: process.env.MIOLO_MAILER_AUTH_METHOD || 'PLAIN',
|
|
252
|
+
... process.env.MIOLO_MAILER_AUTH_METHOD === 'LOGIN'
|
|
253
|
+
? {
|
|
254
|
+
auth: {
|
|
255
|
+
user: process.env.MIOLO_MAILER_SMTP_USER || 'noreply@mail.com',
|
|
256
|
+
pass: process.env.MIOLO_MAILER_SMTP_PASS || '****',
|
|
257
|
+
type: 'login',
|
|
258
|
+
},
|
|
259
|
+
secure: true,
|
|
260
|
+
}
|
|
261
|
+
: {
|
|
262
|
+
secure: false
|
|
263
|
+
},
|
|
264
|
+
|
|
239
265
|
//
|
|
240
266
|
// TLS options
|
|
241
267
|
//
|
|
@@ -244,7 +270,8 @@ export default {
|
|
|
244
270
|
// In most cases set this value to true if you are connecting to port 465. For port 587 or 25 keep it false
|
|
245
271
|
// ** Setting secure to false does not mean that you would not use an encrypted connection. Most SMTP servers allow
|
|
246
272
|
// connection upgrade via STARTTLS command but to use this you have to connect using plaintext first
|
|
247
|
-
|
|
273
|
+
|
|
274
|
+
|
|
248
275
|
// tls – defines additional node.js TLSSocket options to be passed to the socket constructor, eg. {rejectUnauthorized: true}.
|
|
249
276
|
tls: {
|
|
250
277
|
// do not fail on invalid certs
|
|
@@ -297,9 +324,9 @@ export default {
|
|
|
297
324
|
// Read about proxy support in Nodemailer from here: https://nodemailer.com/smtp/proxies/
|
|
298
325
|
},
|
|
299
326
|
defaults: {
|
|
300
|
-
name: 'miolo',
|
|
301
|
-
from: '
|
|
302
|
-
to: '
|
|
327
|
+
name: process.env.MIOLO_NAME || 'miolo',
|
|
328
|
+
from: process.env.MIOLO_MAILER_FROM || 'noreply@mail.com',
|
|
329
|
+
to: process.env.MIOLO_MAILER_TO || 'noreply@mail.com'
|
|
303
330
|
}
|
|
304
331
|
},
|
|
305
332
|
auth: {
|
|
@@ -332,6 +359,7 @@ export default {
|
|
|
332
359
|
// callback: a middleware function
|
|
333
360
|
// }, ...]
|
|
334
361
|
},
|
|
362
|
+
|
|
335
363
|
middlewares: [
|
|
336
364
|
// async (ctx, next) => {}
|
|
337
365
|
// Remember to call `await next()`
|
|
@@ -361,20 +389,22 @@ export default {
|
|
|
361
389
|
host: '127.0.0.1',
|
|
362
390
|
port: 6379
|
|
363
391
|
},
|
|
364
|
-
version: 1,
|
|
392
|
+
version: parseInt(process.env.MIOLO_CACHE_VERSION || 1),
|
|
365
393
|
clean: false,
|
|
366
394
|
},
|
|
367
395
|
|
|
368
396
|
// specific cache options for calustra
|
|
369
397
|
calustra: {
|
|
370
398
|
namespace: 'miolo-calustra',
|
|
371
|
-
ttl: 86400*1000,
|
|
399
|
+
ttl: parseInt(process.env.MIOLO_CACHE_CALUSTRA_TTL || 86400*1000),
|
|
400
|
+
version: parseInt(process.env.MIOLO_CACHE_CALUSTRA_VERSION || process.env.MIOLO_CACHE_VERSION || 1)
|
|
372
401
|
},
|
|
373
402
|
|
|
374
403
|
// specific cache options for koa-session
|
|
375
404
|
session: {
|
|
376
405
|
namespace: 'miolo-session',
|
|
377
|
-
ttl: SESSION_MAX_AGE,
|
|
406
|
+
ttl: parseInt(process.env.MIOLO_CACHE_SESSION_TTL || process.env.MIOLO_SESSION_MAX_AGE || SESSION_MAX_AGE),
|
|
407
|
+
version: parseInt(process.env.MIOLO_CACHE_SESSION_VERSION || process.env.MIOLO_CACHE_VERSION || 1)
|
|
378
408
|
},
|
|
379
409
|
|
|
380
410
|
// custom cache instances
|
|
@@ -404,30 +434,38 @@ export default {
|
|
|
404
434
|
*/
|
|
405
435
|
},
|
|
406
436
|
|
|
407
|
-
|
|
408
|
-
vite: {
|
|
409
|
-
base: '/',
|
|
410
|
-
root: '',
|
|
411
|
-
watch: {
|
|
412
|
-
// During tests we edit the files too fast and sometimes chokidar
|
|
413
|
-
// misses change events, so enforce polling for consistency
|
|
414
|
-
usePolling: true,
|
|
415
|
-
interval: 100,
|
|
416
|
-
},
|
|
417
|
-
},
|
|
437
|
+
build: {
|
|
418
438
|
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
},
|
|
439
|
+
client: process.env.NODE_ENV === 'production'
|
|
440
|
+
? `${process.env.MIOLO_BUILD_CLIENT_DEST}/${process.env.MIOLO_NAME}.${process.env.MIOLO_BUNDLE_SUFFIX}.js`
|
|
441
|
+
: process.env.MIOLO_BUILD_CLIENT_ENTRY,
|
|
442
|
+
|
|
443
|
+
html: process.env.MIOLO_BUILD_HTML_FILE,
|
|
425
444
|
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
|
|
445
|
+
vite: {
|
|
446
|
+
base: '/',
|
|
447
|
+
root: '',
|
|
448
|
+
watch: {
|
|
449
|
+
// During tests we edit the files too fast and sometimes chokidar
|
|
450
|
+
// misses change events, so enforce polling for consistency
|
|
451
|
+
usePolling: true,
|
|
452
|
+
interval: 100,
|
|
453
|
+
},
|
|
454
|
+
},
|
|
455
|
+
|
|
456
|
+
ssr: {
|
|
457
|
+
server: process.env.NODE_ENV === 'production'
|
|
458
|
+
? path.join(process.cwd(), `${process.env.MIOLO_BUILD_SERVER_DEST}/entry-server.js`)
|
|
459
|
+
: process.env.MIOLO_BUILD_SERVER_SSR_ENTRY
|
|
460
|
+
// loader: async (ctx) => {}
|
|
430
461
|
},
|
|
462
|
+
|
|
463
|
+
dev: {
|
|
464
|
+
watcher: {
|
|
465
|
+
enabled: process.env.MIOLO_DEV_WATCH_ENABLED==='true',
|
|
466
|
+
dirs: process.env.MIOLO_DEV_WATCH_DIRS.split(',').map(dir => path.join(process.cwd(), dir)),
|
|
467
|
+
},
|
|
468
|
+
}
|
|
431
469
|
}
|
|
432
470
|
};
|
|
433
471
|
|
|
@@ -1,5 +1,22 @@
|
|
|
1
|
+
import path from 'path'
|
|
2
|
+
import { readFileSync } from 'fs'
|
|
1
3
|
import { fallbackIndexHTML } from './fallbackIndex.mjs'
|
|
2
4
|
|
|
5
|
+
function _html_read(htmlFile) {
|
|
6
|
+
try {
|
|
7
|
+
const isProduction = process.env.NODE_ENV === 'production'
|
|
8
|
+
const proot = (p) => path.join(process.cwd(), p)
|
|
9
|
+
const indexHTMLPath= proot(isProduction
|
|
10
|
+
? `${process.env.MIOLO_BUILD_CLIENT_DEST}/index.html`
|
|
11
|
+
: htmlFile)
|
|
12
|
+
|
|
13
|
+
const indexHTML = readFileSync(indexHTMLPath, 'utf8')
|
|
14
|
+
return indexHTML
|
|
15
|
+
} catch(error) {
|
|
16
|
+
console.error(`[miolo] Error reading HTML file ${htmlFile}: ${error}`)
|
|
17
|
+
return fallbackIndexHTML
|
|
18
|
+
}
|
|
19
|
+
}
|
|
3
20
|
|
|
4
21
|
|
|
5
22
|
function _add_client_script_to_body(htmlString, client) {
|
|
@@ -27,11 +44,11 @@ function _add_client_script_to_body(htmlString, client) {
|
|
|
27
44
|
|
|
28
45
|
|
|
29
46
|
// HTML renderer
|
|
30
|
-
export const ssr_html_renderer_make = async (app, ssrConfig, devRender= undefined) => {
|
|
47
|
+
export const ssr_html_renderer_make = async (app, ssrConfig, htmlFile, client, devRender= undefined) => {
|
|
31
48
|
const isProduction = process.env.NODE_ENV === 'production'
|
|
32
49
|
|
|
33
50
|
// check HTML
|
|
34
|
-
let tmplHtml =
|
|
51
|
+
let tmplHtml = _html_read(htmlFile)
|
|
35
52
|
for (const vrb of ['{context}', '{children}']) {
|
|
36
53
|
if (tmplHtml.indexOf(vrb) < 0) {
|
|
37
54
|
app.context.miolo.logger.error(`[ssr] Provided HTML for rendering has no ${vrb} template variable`)
|
|
@@ -81,7 +98,7 @@ export const ssr_html_renderer_make = async (app, ssrConfig, devRender= undefine
|
|
|
81
98
|
.replace('{context}', JSON.stringify(context, null, 2))
|
|
82
99
|
.replace('{children}', ssr_html)
|
|
83
100
|
|
|
84
|
-
parsed_html = _add_client_script_to_body(parsed_html,
|
|
101
|
+
parsed_html = _add_client_script_to_body(parsed_html, client)
|
|
85
102
|
|
|
86
103
|
return parsed_html
|
|
87
104
|
}
|
|
@@ -5,14 +5,14 @@ import { ssr_html_renderer_make } from './html.mjs'
|
|
|
5
5
|
|
|
6
6
|
export async function init_ssr_render_middleware(app, config, devRender= undefined) {
|
|
7
7
|
|
|
8
|
-
const ssrConfig = config.ssr
|
|
8
|
+
const ssrConfig = config.build.ssr
|
|
9
9
|
const httpConfig = config.http
|
|
10
10
|
const authConfig = config?.auth || {}
|
|
11
11
|
// const socketConfig = config?.socket || {}
|
|
12
12
|
|
|
13
13
|
const ssr_build_context = ssr_context_builder_make(app, ssrConfig)
|
|
14
14
|
const ssr_loader = ssr_loader_make(app, ssrConfig)
|
|
15
|
-
const ssr_html_renderer = await ssr_html_renderer_make(app, ssrConfig, devRender)
|
|
15
|
+
const ssr_html_renderer = await ssr_html_renderer_make(app, ssrConfig, config.build.html, config.build.client, devRender)
|
|
16
16
|
|
|
17
17
|
async function render_ssr_middleware(ctx) {
|
|
18
18
|
try {
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
import koaConnect from 'koa-connect'
|
|
3
3
|
|
|
4
4
|
// Vite Dev Server
|
|
5
|
-
export async function init_vite_dev_server_middleware(app,
|
|
5
|
+
export async function init_vite_dev_server_middleware(app, viteConfig) {
|
|
6
6
|
const isProduction = process.env.NODE_ENV === 'production'
|
|
7
7
|
let vite
|
|
8
8
|
|
|
@@ -22,17 +22,17 @@ export async function init_vite_dev_server_middleware(app, config) {
|
|
|
22
22
|
}
|
|
23
23
|
}
|
|
24
24
|
)],
|
|
25
|
+
...viteConfig || {},
|
|
25
26
|
//
|
|
26
|
-
base:
|
|
27
|
-
root:
|
|
27
|
+
base: viteConfig?.base || '/',
|
|
28
|
+
root: viteConfig?.root || '',
|
|
28
29
|
watch: {
|
|
29
30
|
// During tests we edit the files too fast and sometimes chokidar
|
|
30
31
|
// misses change events, so enforce polling for consistency
|
|
31
32
|
usePolling: true,
|
|
32
33
|
interval: 100,
|
|
33
|
-
...
|
|
34
|
-
}
|
|
35
|
-
...config?.vite || {}
|
|
34
|
+
...viteConfig?.vite?.watch || {}
|
|
35
|
+
}
|
|
36
36
|
})
|
|
37
37
|
|
|
38
38
|
app.use(koaConnect(vite.middlewares))
|
|
@@ -18,8 +18,8 @@ export async function miolo_dev(sconfig) {
|
|
|
18
18
|
|
|
19
19
|
// Vite DEV server init
|
|
20
20
|
const devInit= async (app, config) => {
|
|
21
|
-
await init_vite_dev_server_middleware(app, config.vite)
|
|
22
|
-
await init_watcher_dev_server_middleware(app, config.dev.watcher, config.ssr)
|
|
21
|
+
await init_vite_dev_server_middleware(app, config.build.vite)
|
|
22
|
+
await init_watcher_dev_server_middleware(app, config.build.dev.watcher, config.build.ssr)
|
|
23
23
|
}
|
|
24
24
|
|
|
25
25
|
// Vite SSR side
|
|
@@ -1,5 +1,3 @@
|
|
|
1
|
-
import '@dotenvx/dotenvx/config'
|
|
2
|
-
|
|
3
1
|
import Koa from 'koa'
|
|
4
2
|
import { init_config } from './config/index.mjs'
|
|
5
3
|
|
|
@@ -41,7 +39,7 @@ async function miolo(sconfig, devInit= undefined, devRender= undefined) {
|
|
|
41
39
|
// Vite Dev Server
|
|
42
40
|
if (devInit) {
|
|
43
41
|
await devInit(app, config)
|
|
44
|
-
// await init_vite_dev_server_middleware(app, config.vite)
|
|
42
|
+
// await init_vite_dev_server_middleware(app, config.build.vite)
|
|
45
43
|
}
|
|
46
44
|
|
|
47
45
|
|
package/README.md
DELETED
|
@@ -1,69 +0,0 @@
|
|
|
1
|
-
# miolo
|
|
2
|
-
[](https://www.npmjs.com/package/miolo)
|
|
3
|
-
[](https://www.npmjs.com/package/miolo)
|
|
4
|
-
|
|
5
|
-

|
|
6
|
-
|
|
7
|
-
---
|
|
8
|
-
|
|
9
|
-
> **[miolo](https://academia.gal/dicionario/-/termo/miolo)**. substantivo masculino plural:
|
|
10
|
-
|
|
11
|
-
> **1.** popular **Encéfalo.**
|
|
12
|
-
|
|
13
|
-
> _Disque aínda se vían os miolos esparexidos polo chan._
|
|
14
|
-
|
|
15
|
-
> substantivo masculino:
|
|
16
|
-
|
|
17
|
-
> **2. Parte interior do pan.**
|
|
18
|
-
|
|
19
|
-
> _Prefiro o miolo á codia._
|
|
20
|
-
|
|
21
|
-
> **4.** figurado **Parte fundamental ou máis importante de algo.**
|
|
22
|
-
|
|
23
|
-
> _O miolo da cuestión non é ese._
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
---
|
|
27
|
-
|
|
28
|
-
# Intro
|
|
29
|
-
|
|
30
|
-
[`miolo`](https://www.afialapis.com/os/miolo) is an all-in-one koa-based server.
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
## Server middleware
|
|
34
|
-
|
|
35
|
-
## init
|
|
36
|
-
|
|
37
|
-
```miolo(config, render)```
|
|
38
|
-
|
|
39
|
-
config: ver defaults.js
|
|
40
|
-
|
|
41
|
-
render:
|
|
42
|
-
undefined => renderiza un html fallback
|
|
43
|
-
html (string) => renderiza ese HTML
|
|
44
|
-
middleware => renderiza HTML con posibilidad de SSR
|
|
45
|
-
|
|
46
|
-
### Custom `ctx` properties
|
|
47
|
-
|
|
48
|
-
ctx.request.body
|
|
49
|
-
ctx.request.ip
|
|
50
|
-
|
|
51
|
-
From koa-passport:
|
|
52
|
-
|
|
53
|
-
ctx.isAuthenticated()
|
|
54
|
-
ctx.isUnauthenticated()
|
|
55
|
-
await ctx.login()
|
|
56
|
-
ctx.logout()
|
|
57
|
-
ctx.state.user
|
|
58
|
-
|
|
59
|
-
From auth:
|
|
60
|
-
ctx.session.user
|
|
61
|
-
ctx.session.authenticated
|
|
62
|
-
ctx.session.token (if guest auth)
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
# Changelog
|
|
68
|
-
|
|
69
|
-
See [changelog here](https://github.com/afialapis/miolo/blob/main/CHANGELOG.md)
|