miolo 3.0.0-beta.13 → 3.0.0-beta.130
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/{dev.mjs → dev/dev.mjs} +19 -5
- package/bin/{dev_start.mjs → dev/dev_start.mjs} +3 -2
- package/bin/index.mjs +47 -33
- package/bin/prod-bin/create-bin.mjs +33 -0
- package/bin/prod-bin/run.mjs +35 -0
- package/bin/{build-client.mjs → prod-build/build-client.mjs} +17 -5
- package/bin/{build-server.mjs → prod-build/build-server.mjs} +12 -10
- package/bin/prod-run/pid.mjs +13 -0
- package/bin/{restart.mjs → prod-run/restart.mjs} +3 -4
- package/bin/prod-run/start.mjs +14 -0
- package/bin/{stop.mjs → prod-run/stop.mjs} +4 -3
- package/bin/util.mjs +2 -29
- package/package.json +25 -26
- package/{bin → src/config}/.env +17 -6
- package/src/config/defaults.mjs +443 -422
- package/src/config/env.mjs +52 -0
- package/src/config/index.mjs +17 -10
- package/src/config/util.mjs +41 -0
- package/src/engines/emailer/queue.mjs +3 -2
- package/src/engines/emailer/transporter.mjs +10 -9
- package/src/engines/http/index.mjs +1 -1
- package/src/engines/parser/Parser.mjs +25 -7
- package/src/engines/schema/index.mjs +40 -0
- package/src/index.mjs +3 -1
- package/src/middleware/auth/basic.mjs +5 -2
- package/src/middleware/auth/credentials/index.mjs +75 -43
- package/src/middleware/auth/credentials/session/index.mjs +7 -0
- package/src/middleware/auth/credentials/session/store.mjs +9 -0
- package/src/middleware/context/index.mjs +1 -1
- package/src/middleware/http/catcher.mjs +78 -2
- package/src/middleware/http/catcher.old.mjs +82 -0
- package/src/middleware/http/custom_blacklist.mjs +3 -1
- package/src/middleware/routes/catch_js_error.mjs +14 -2
- package/src/middleware/routes/router/crud/attachCrudRoutes.mjs +24 -12
- package/src/middleware/routes/router/crud/getCrudConfig.mjs +4 -6
- package/src/middleware/routes/router/defaults.mjs +1 -11
- package/src/middleware/routes/router/index.mjs +0 -1
- package/src/middleware/routes/router/queries/attachQueriesRoutes.mjs +70 -13
- package/src/middleware/routes/router/queries/getQueriesConfig.mjs +21 -21
- package/src/middleware/routes/router/utils.mjs +20 -21
- package/src/middleware/ssr/context.mjs +1 -1
- package/src/middleware/ssr/fallbackIndex.mjs +2 -8
- package/src/middleware/ssr/html.mjs +39 -31
- package/src/middleware/vite/devserver.mjs +22 -8
- package/src/server-cron.mjs +3 -4
- package/src/server-dev.mjs +3 -3
- package/src/server.mjs +3 -5
- package/bin/create-bin.mjs +0 -38
- package/bin/env.mjs +0 -39
- package/bin/prod_start.mjs +0 -9
- package/bin/start.mjs +0 -17
- package/src/engines/logger/verify.mjs +0 -22
|
@@ -3,6 +3,7 @@ import path from 'node:path'
|
|
|
3
3
|
import { fileURLToPath } from 'node:url'
|
|
4
4
|
import { fork } from 'node:child_process'
|
|
5
5
|
|
|
6
|
+
|
|
6
7
|
const __filename = fileURLToPath(import.meta.url)
|
|
7
8
|
const __dirname = path.dirname(__filename)
|
|
8
9
|
|
|
@@ -19,9 +20,19 @@ function _isProcessRunning(pid) {
|
|
|
19
20
|
}
|
|
20
21
|
}
|
|
21
22
|
|
|
22
|
-
async function startDevServerProcess({ appName }) {
|
|
23
|
+
async function startDevServerProcess({ appName, debug }) {
|
|
23
24
|
const serverPath = path.join(__dirname, './dev_start.mjs')
|
|
24
|
-
|
|
25
|
+
|
|
26
|
+
const execArgv = [];
|
|
27
|
+
if (debug===true) {
|
|
28
|
+
const newDebugPort = process.debugPort + 1;
|
|
29
|
+
console.log(`[${appName}][dev] Debugging enabled. Attaching debugger to child process on port ${newDebugPort}`);
|
|
30
|
+
execArgv.push(`--inspect=${newDebugPort}`);
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
serverProcess = fork(serverPath, [], {
|
|
34
|
+
execArgv: execArgv
|
|
35
|
+
})
|
|
25
36
|
|
|
26
37
|
console.log(`[${appName}][dev] Server process started with pid ${serverProcess.pid} from ${process.pid}`)
|
|
27
38
|
|
|
@@ -59,13 +70,16 @@ async function startDevServerProcess({ appName }) {
|
|
|
59
70
|
}, 2000)
|
|
60
71
|
}
|
|
61
72
|
|
|
62
|
-
startDevServerProcess({ appName }) // Inicia un nuevo proceso
|
|
73
|
+
startDevServerProcess({ appName, debug }) // Inicia un nuevo proceso
|
|
63
74
|
}
|
|
64
75
|
})
|
|
65
76
|
}
|
|
66
77
|
|
|
67
78
|
|
|
68
|
-
export default async function(appName) {
|
|
79
|
+
export default async function(appName= undefined, debug= false) {
|
|
80
|
+
// Based on command line params or .env
|
|
81
|
+
appName = appName || process.env.MIOLO_NAME
|
|
82
|
+
|
|
69
83
|
console.log(`[${appName}][dev] Running DEV server`)
|
|
70
|
-
await startDevServerProcess({ appName })
|
|
84
|
+
await startDevServerProcess({ appName, debug })
|
|
71
85
|
}
|
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
import path from 'node:path'
|
|
2
|
-
import {miolo_dev} from '
|
|
2
|
+
import {miolo_dev} from '../../src/server-dev.mjs'
|
|
3
3
|
|
|
4
4
|
async function _miolo_dev_start_server() {
|
|
5
|
-
|
|
5
|
+
process.env.NODE_ENV = 'development'
|
|
6
|
+
const config = await import(path.join(process.cwd(), process.env.MIOLO_DEV_CONFIG_ENTRY))
|
|
6
7
|
const app = await miolo_dev(config.default)
|
|
7
8
|
await app.start()
|
|
8
9
|
return app
|
package/bin/index.mjs
CHANGED
|
@@ -1,69 +1,83 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
+
import path from 'node:path'
|
|
2
3
|
import yargs from 'yargs-parser'
|
|
3
|
-
import {
|
|
4
|
-
import { init_env_config } from './env.mjs'
|
|
4
|
+
import { init_env_config } from '../src/config/env.mjs'
|
|
5
5
|
|
|
6
6
|
|
|
7
7
|
async function main() {
|
|
8
8
|
const args = yargs(process.argv.slice(2))
|
|
9
9
|
const command = args._[0]
|
|
10
10
|
|
|
11
|
+
// Init env
|
|
12
|
+
process.env.NODE_ENV = 'production'
|
|
13
|
+
init_env_config()
|
|
14
|
+
|
|
15
|
+
// Init vars
|
|
16
|
+
const appName = args['app-name'] || process.env.MIOLO_NAME
|
|
17
|
+
const serverExt = 'node.bundle.mjs'
|
|
18
|
+
|
|
11
19
|
try {
|
|
12
|
-
init_env_config()
|
|
13
|
-
const appName = process.env.MIOLO_NAME
|
|
14
|
-
intre_locale_init(process.env.MIOLO_INTRE_LOCALE)
|
|
15
20
|
|
|
16
21
|
switch (command) {
|
|
17
22
|
case 'dev':
|
|
18
23
|
process.env.NODE_ENV = 'development'
|
|
19
|
-
const devHandler = (await import ('./dev.mjs')).default
|
|
24
|
+
const devHandler = (await import ('./dev/dev.mjs')).default
|
|
20
25
|
await devHandler(appName)
|
|
21
26
|
break
|
|
27
|
+
|
|
28
|
+
case 'deb':
|
|
29
|
+
process.env.NODE_ENV = 'development'
|
|
30
|
+
const debHandler = (await import ('./dev/dev.mjs')).default
|
|
31
|
+
await debHandler(appName, true)
|
|
32
|
+
break
|
|
22
33
|
|
|
23
34
|
case 'build-client':
|
|
24
|
-
process.env.
|
|
25
|
-
const buildClientHandler = (await import ('./build-client.mjs')).default
|
|
26
|
-
const clientEntry = args.entry || process.env.MIOLO_BUILD_CLIENT_ENTRY
|
|
35
|
+
const entry = args.entry || process.env.MIOLO_BUILD_CLIENT_ENTRY
|
|
27
36
|
const htmlFile = args['html-file'] || process.env.MIOLO_BUILD_HTML_FILE
|
|
28
|
-
const
|
|
29
|
-
|
|
37
|
+
const cliDest = args.dest || process.env.MIOLO_BUILD_CLIENT_DEST
|
|
38
|
+
|
|
39
|
+
const buildClientHandler = (await import ('./prod-build/build-client.mjs')).default
|
|
40
|
+
await buildClientHandler(appName, entry, htmlFile, cliDest)
|
|
30
41
|
break
|
|
31
42
|
|
|
32
43
|
case 'build-server':
|
|
33
|
-
|
|
34
|
-
const
|
|
35
|
-
const ssrEntry
|
|
36
|
-
const ssrDest
|
|
37
|
-
const
|
|
38
|
-
|
|
44
|
+
// Based on command line params or .env
|
|
45
|
+
const srvEntry= args['entry'] || process.env.MIOLO_BUILD_SERVER_ENTRY
|
|
46
|
+
const ssrEntry= args['ssr-entry'] || process.env.MIOLO_BUILD_SERVER_SSR_ENTRY
|
|
47
|
+
const ssrDest= args['ssr-dest'] || process.env.MIOLO_BUILD_SERVER_DEST
|
|
48
|
+
const srvDest= args.dest || process.env.MIOLO_BUILD_SERVER_DEST
|
|
49
|
+
|
|
50
|
+
const buildServerHandler = (await import ('./prod-build/build-server.mjs')).default
|
|
51
|
+
await buildServerHandler(appName, ssrEntry, ssrDest, srvEntry, srvDest)
|
|
39
52
|
break
|
|
40
53
|
|
|
41
54
|
case 'start':
|
|
42
|
-
|
|
43
|
-
const
|
|
44
|
-
|
|
45
|
-
|
|
55
|
+
|
|
56
|
+
const destFile = args.dest || path.join(process.cwd(), `${process.env.MIOLO_BUILD_SERVER_DEST}/${appName}.${serverExt}`)
|
|
57
|
+
|
|
58
|
+
const startHandler = (await import ('./prod-run/start.mjs')).default
|
|
59
|
+
await startHandler(appName, destFile)
|
|
46
60
|
break
|
|
47
61
|
|
|
48
62
|
case 'stop':
|
|
49
|
-
|
|
50
|
-
const stopHandler = (await import ('./stop.mjs')).default
|
|
63
|
+
const stopHandler = (await import ('./prod-run/stop.mjs')).default
|
|
51
64
|
await stopHandler(appName)
|
|
52
65
|
break
|
|
53
66
|
|
|
54
67
|
case 'restart':
|
|
55
|
-
process.env.
|
|
56
|
-
|
|
57
|
-
const
|
|
58
|
-
await restartHandler(
|
|
68
|
+
const restartDestFile = args.dest || path.join(process.cwd(), `${process.env.MIOLO_BUILD_SERVER_DEST}/${appName}.${serverExt}`)
|
|
69
|
+
|
|
70
|
+
const restartHandler = (await import ('./prod-run/restart.mjs')).default
|
|
71
|
+
await restartHandler(appName, restartDestFile)
|
|
59
72
|
break
|
|
60
73
|
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
74
|
+
case 'create-bin':
|
|
75
|
+
const dest = args.dest || process.env.MIOLO_BUILD_SERVER_DEST
|
|
76
|
+
const cbinDestFile = `./${appName}.${serverExt}`
|
|
77
|
+
|
|
78
|
+
const createHandler = (await import ('./prod-bin/create-bin.mjs')).default
|
|
79
|
+
await createHandler(appName, dest, cbinDestFile)
|
|
80
|
+
break
|
|
67
81
|
|
|
68
82
|
default:
|
|
69
83
|
console.error(`[miolo] Unknown command: ${command}`)
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import {readFileSync, writeFileSync} from 'node:fs'
|
|
2
|
+
import path from 'path'
|
|
3
|
+
import { fileURLToPath } from 'url'
|
|
4
|
+
import { copyFileSync } from '../util.mjs'
|
|
5
|
+
|
|
6
|
+
const __my_filename = fileURLToPath(import.meta.url)
|
|
7
|
+
const __my_dirname = path.dirname(__my_filename)
|
|
8
|
+
|
|
9
|
+
export default async function(appName, dest, destFile) {
|
|
10
|
+
console.log(`[${appName}][prod][create-bin] Creating bin files...`)
|
|
11
|
+
|
|
12
|
+
const readSource = (f) => readFileSync(path.resolve(__my_dirname, '../prod-run', f), {encoding:'utf8'})
|
|
13
|
+
const writeDest = (f, content) => writeFileSync(path.join(process.cwd(), dest, f), content, {encoding:'utf8',flag:'w'})
|
|
14
|
+
|
|
15
|
+
const pidContent = readSource('./pid.mjs')
|
|
16
|
+
writeDest('pid.mjs', pidContent)
|
|
17
|
+
|
|
18
|
+
let startContent = readSource('./start.mjs')
|
|
19
|
+
startContent = startContent.replace('(appName, destFile) {', `(appName= '${appName}', destFile= '${destFile}') {`)
|
|
20
|
+
writeDest('start.mjs', startContent)
|
|
21
|
+
|
|
22
|
+
let stopContent = readSource('./stop.mjs')
|
|
23
|
+
stopContent = stopContent.replace('(appName) {', `(appName= '${appName}') {`)
|
|
24
|
+
writeDest('stop.mjs', stopContent)
|
|
25
|
+
|
|
26
|
+
let restartContent = readSource('./restart.mjs')
|
|
27
|
+
restartContent = restartContent.replace('(appName, destFile) {', `(appName= '${appName}', destFile= '${destFile}') {`)
|
|
28
|
+
writeDest('restart.mjs', restartContent)
|
|
29
|
+
|
|
30
|
+
copyFileSync(path.join(__my_dirname, './run.mjs'), path.join(process.cwd(), dest, 'run.mjs'))
|
|
31
|
+
copyFileSync(path.join(__my_dirname, '../../src/config/.env'), path.join(process.cwd(), dest, '.env'))
|
|
32
|
+
|
|
33
|
+
}
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
async function miolo_run() {
|
|
3
|
+
const args = process.argv.slice(2)
|
|
4
|
+
const command = args[0]
|
|
5
|
+
process.env.NODE_ENV = 'production'
|
|
6
|
+
|
|
7
|
+
try {
|
|
8
|
+
switch (command) {
|
|
9
|
+
case 'start':
|
|
10
|
+
const startHandler = (await import ('./start.mjs')).default
|
|
11
|
+
await startHandler()
|
|
12
|
+
break
|
|
13
|
+
|
|
14
|
+
case 'stop':
|
|
15
|
+
const stopHandler = (await import ('./stop.mjs')).default
|
|
16
|
+
await stopHandler()
|
|
17
|
+
break
|
|
18
|
+
|
|
19
|
+
case 'restart':
|
|
20
|
+
const restartHandler = (await import ('./restart.mjs')).default
|
|
21
|
+
await restartHandler()
|
|
22
|
+
break
|
|
23
|
+
|
|
24
|
+
default:
|
|
25
|
+
console.error(`[miolo] Unknown command: ${command}`)
|
|
26
|
+
console.log('[miolo] Available commands: start, stop, restart')
|
|
27
|
+
process.exit(1)
|
|
28
|
+
}
|
|
29
|
+
} catch (error) {
|
|
30
|
+
console.error('[miolo] Error during command execution:', error)
|
|
31
|
+
process.exit(1)
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
miolo_run()
|
|
@@ -1,9 +1,18 @@
|
|
|
1
1
|
|
|
2
|
+
import path from 'node:path'
|
|
2
3
|
import {xeiraBundle} from 'xeira'
|
|
3
|
-
import {
|
|
4
|
+
import { nanoid } from 'nanoid'
|
|
5
|
+
import { cleanFolder, copyFileSync, isFileExistingSync } from '../util.mjs'
|
|
4
6
|
|
|
5
7
|
function _addCssLinkToHead(appName, htmlString, dest) {
|
|
6
|
-
|
|
8
|
+
|
|
9
|
+
const webDest = dest.startsWith('./')
|
|
10
|
+
? dest.replace('./', '/')
|
|
11
|
+
: dest.startsWith('/')
|
|
12
|
+
? dest
|
|
13
|
+
: `/${dest}`
|
|
14
|
+
|
|
15
|
+
const linkTag = ` <link href="${webDest}/${appName}.${process.env.MIOLO_BUILD_CLIENT_SUFFIX}.css?v=${nanoid()}" rel="stylesheet" media="all">`
|
|
7
16
|
|
|
8
17
|
// Expresión regular para encontrar la etiqueta </head> de cierre.
|
|
9
18
|
// Usamos un grupo de captura para mantener el contenido antes de </head>.
|
|
@@ -28,25 +37,28 @@ function _addCssLinkToHead(appName, htmlString, dest) {
|
|
|
28
37
|
export default async function(appName, entry, htmlFile, dest) {
|
|
29
38
|
console.log(`[${appName}][prod] Building client from entry ${entry}`)
|
|
30
39
|
|
|
40
|
+
// Clean dest folder
|
|
31
41
|
cleanFolder(dest)
|
|
32
42
|
|
|
43
|
+
// Build client
|
|
33
44
|
await xeiraBundle({
|
|
34
45
|
source_index: entry,
|
|
35
46
|
target: 'browser',
|
|
36
47
|
bundle_folder: dest,
|
|
37
48
|
bundle_name: appName,
|
|
38
|
-
bundle_extension: process.env.
|
|
49
|
+
bundle_extension: process.env.MIOLO_BUILD_CLIENT_SUFFIX,
|
|
39
50
|
bundler: 'rollup',
|
|
40
51
|
bundle_node_polyfill: true
|
|
41
52
|
})
|
|
42
53
|
|
|
43
|
-
|
|
54
|
+
// Fix css file
|
|
55
|
+
const destCssFile = `${dest}/${appName}.${process.env.MIOLO_BUILD_CLIENT_SUFFIX}.css`
|
|
44
56
|
const destCssFileExists = isFileExistingSync(destCssFile)
|
|
45
57
|
|
|
46
58
|
console.log(`[${appName}][prod] destCssFile ${destCssFile} exists?: ${destCssFileExists}`)
|
|
47
59
|
|
|
48
60
|
console.log(`[${appName}][prod] Copying HTML file ${htmlFile} to ${dest}/index.html`)
|
|
49
|
-
copyFileSync(htmlFile, `${dest}/index.html
|
|
61
|
+
copyFileSync(path.join(process.cwd(), htmlFile), path.join(process.cwd(), `${dest}/index.html`), (content) => {
|
|
50
62
|
if (destCssFileExists) {
|
|
51
63
|
content = _addCssLinkToHead(appName, content, dest)
|
|
52
64
|
}
|
|
@@ -3,8 +3,7 @@ import path from 'node:path'
|
|
|
3
3
|
import { readFile, writeFile} from 'node:fs/promises'
|
|
4
4
|
import { build } from 'vite'
|
|
5
5
|
import {xeiraBundle} from 'xeira'
|
|
6
|
-
import { cleanFolder } from '
|
|
7
|
-
|
|
6
|
+
import { cleanFolder } from '../util.mjs'
|
|
8
7
|
|
|
9
8
|
|
|
10
9
|
export async function _fixProdBuild(appName, filePath) {
|
|
@@ -21,10 +20,13 @@ export async function _fixProdBuild(appName, filePath) {
|
|
|
21
20
|
}
|
|
22
21
|
}
|
|
23
22
|
|
|
24
|
-
export default async function(appName, ssrEntry, ssrDest,
|
|
25
|
-
cleanFolder(dest)
|
|
26
|
-
|
|
23
|
+
export default async function(appName, ssrEntry, ssrDest, srvEntry, srvDest) {
|
|
27
24
|
console.log(`[${appName}][prod] Building first the SSR entry ${ssrEntry}`)
|
|
25
|
+
|
|
26
|
+
// clean dest folder
|
|
27
|
+
cleanFolder(srvDest)
|
|
28
|
+
|
|
29
|
+
// Build SSR entry
|
|
28
30
|
await build({
|
|
29
31
|
build: {
|
|
30
32
|
outDir: path.resolve(process.cwd(), ssrDest),
|
|
@@ -35,15 +37,15 @@ export default async function(appName, ssrEntry, ssrDest, dest) {
|
|
|
35
37
|
ssr: {
|
|
36
38
|
noExternal: true
|
|
37
39
|
}
|
|
38
|
-
})
|
|
40
|
+
})
|
|
39
41
|
|
|
42
|
+
console.log(`[${appName}][prod] Building server entry for ${srvEntry}`)
|
|
40
43
|
|
|
41
44
|
const serverExt = 'node.bundle.mjs'
|
|
42
45
|
await xeiraBundle({
|
|
43
|
-
|
|
44
|
-
source_index: '../miolo/bin/prod_start.mjs',
|
|
46
|
+
source_index: srvEntry,
|
|
45
47
|
target: 'node',
|
|
46
|
-
bundle_folder:
|
|
48
|
+
bundle_folder: srvDest,
|
|
47
49
|
bundle_name: appName,
|
|
48
50
|
bundle_extension: serverExt,
|
|
49
51
|
bundler: 'rollup',
|
|
@@ -51,6 +53,6 @@ export default async function(appName, ssrEntry, ssrDest, dest) {
|
|
|
51
53
|
})
|
|
52
54
|
|
|
53
55
|
console.log(`[${appName}][prod] Fixing server build (prod)...`)
|
|
54
|
-
const destFile = path.join(process.cwd(), `${
|
|
56
|
+
const destFile = path.join(process.cwd(), `${srvDest}/${appName}.${serverExt}`)
|
|
55
57
|
await _fixProdBuild(appName, destFile)
|
|
56
58
|
}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import {writeFileSync, readFileSync} from 'node:fs'
|
|
2
|
+
|
|
3
|
+
export function pidFileCreate(appName) {
|
|
4
|
+
const pidFilePath = `/tmp/${appName}.pid`
|
|
5
|
+
writeFileSync(pidFilePath, `${process.pid}`, {encoding:'utf8',flag:'w'})
|
|
6
|
+
return process.pid
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
export function pidFileRead(appName) {
|
|
10
|
+
const pidFilePath = `/tmp/${appName}.pid`
|
|
11
|
+
const pid = readFileSync(pidFilePath, {encoding:'utf8'})
|
|
12
|
+
return pid
|
|
13
|
+
}
|
|
@@ -1,10 +1,9 @@
|
|
|
1
1
|
import start from "./start.mjs"
|
|
2
2
|
import stop from "./stop.mjs"
|
|
3
3
|
|
|
4
|
-
export default async function(appName,
|
|
4
|
+
export default async function restart(appName, destFile) {
|
|
5
5
|
console.log(`[${appName}][prod][restart] Restarting server...`)
|
|
6
6
|
|
|
7
7
|
await stop(appName)
|
|
8
|
-
await start(appName,
|
|
9
|
-
|
|
10
|
-
}
|
|
8
|
+
await start(appName, destFile)
|
|
9
|
+
}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { pidFileCreate } from "./pid.mjs"
|
|
2
|
+
|
|
3
|
+
export default async function start(appName, destFile) {
|
|
4
|
+
// Start server
|
|
5
|
+
console.log(`[${appName}][prod][start] Starting server from ${destFile}...`)
|
|
6
|
+
|
|
7
|
+
const srv_module = await import(destFile)
|
|
8
|
+
const server = srv_module.default
|
|
9
|
+
|
|
10
|
+
const pid = pidFileCreate(appName)
|
|
11
|
+
console.log(`[${appName}][prod][start] Starting server. PID is ${pid}...`)
|
|
12
|
+
|
|
13
|
+
await server()
|
|
14
|
+
}
|
|
@@ -1,6 +1,7 @@
|
|
|
1
|
-
import { pidFileRead } from "./
|
|
1
|
+
import { pidFileRead } from "./pid.mjs"
|
|
2
2
|
|
|
3
|
-
export default async function(appName) {
|
|
3
|
+
export default async function stop(appName) {
|
|
4
|
+
// stop server by killin gprocess
|
|
4
5
|
console.log(`[${appName}][prod][stop] Stopping server...`)
|
|
5
6
|
|
|
6
7
|
try {
|
|
@@ -16,4 +17,4 @@ export default async function(appName) {
|
|
|
16
17
|
|
|
17
18
|
return 0
|
|
18
19
|
}
|
|
19
|
-
}
|
|
20
|
+
}
|
package/bin/util.mjs
CHANGED
|
@@ -2,40 +2,13 @@ import {readdirSync, rmSync, writeFileSync, readFileSync} from 'node:fs'
|
|
|
2
2
|
import path from 'node:path'
|
|
3
3
|
|
|
4
4
|
|
|
5
|
-
// export function getAppName() {
|
|
6
|
-
// try {
|
|
7
|
-
// const packageJsonPath = path.join(process.cwd(), 'package.json')
|
|
8
|
-
// const content = readFileSync(packageJsonPath, 'utf8')
|
|
9
|
-
// const packageData = JSON.parse(content)
|
|
10
|
-
// return packageData.name
|
|
11
|
-
// } catch (error) {
|
|
12
|
-
// console.error('[miolo] Error reading package.json:', error)
|
|
13
|
-
// return 'miolo'
|
|
14
|
-
// }
|
|
15
|
-
// }
|
|
16
|
-
|
|
17
5
|
export function cleanFolder(folder) {
|
|
18
6
|
readdirSync(folder).forEach(file => {
|
|
19
7
|
rmSync(`${folder}/${file}`, { recursive: true, force: true });
|
|
20
8
|
})
|
|
21
9
|
}
|
|
22
10
|
|
|
23
|
-
|
|
24
|
-
export function pidFileCreate(appName) {
|
|
25
|
-
const pidFilePath = `/tmp/${appName}.pid`
|
|
26
|
-
writeFileSync(pidFilePath, `${process.pid}`, {encoding:'utf8',flag:'w'})
|
|
27
|
-
return process.pid
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
export function pidFileRead(appName) {
|
|
31
|
-
const pidFilePath = `/tmp/${appName}.pid`
|
|
32
|
-
const pid = readFileSync(pidFilePath, {encoding:'utf8'})
|
|
33
|
-
return pid
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
export function copyFileSync(src, dest, modifier= undefined) {
|
|
37
|
-
const srcPath = path.join(process.cwd(), src)
|
|
38
|
-
const destPath = path.join(process.cwd(), dest)
|
|
11
|
+
export function copyFileSync(srcPath, destPath, modifier= undefined) {
|
|
39
12
|
try {
|
|
40
13
|
let content = readFileSync(srcPath, 'utf8')
|
|
41
14
|
if (modifier) {
|
|
@@ -56,4 +29,4 @@ export function isFileExistingSync(filePath) {
|
|
|
56
29
|
console.error(`[miolo] Error checking if file exists: ${filePath}`, error)
|
|
57
30
|
return false
|
|
58
31
|
}
|
|
59
|
-
}
|
|
32
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "miolo",
|
|
3
|
-
"version": "3.0.0-beta.
|
|
3
|
+
"version": "3.0.0-beta.130",
|
|
4
4
|
"description": "all-in-one koa-based server",
|
|
5
5
|
"author": "Donato Lorenzo <donato@afialapis.com>",
|
|
6
6
|
"contributors": [
|
|
@@ -20,43 +20,41 @@
|
|
|
20
20
|
},
|
|
21
21
|
"type": "module",
|
|
22
22
|
"exports": {
|
|
23
|
-
"
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
"default": "./dist/miolo.node.mjs"
|
|
27
|
-
},
|
|
28
|
-
"./server-dev": {
|
|
29
|
-
"default": "./src/server-dev.mjs"
|
|
30
|
-
}
|
|
23
|
+
"node": "./src/index.mjs",
|
|
24
|
+
"import": "./src/index.mjs",
|
|
25
|
+
"default": "./dist/miolo.node.mjs"
|
|
31
26
|
},
|
|
32
27
|
"files": [
|
|
33
28
|
"bin",
|
|
34
29
|
"src"
|
|
35
30
|
],
|
|
36
31
|
"scripts": {
|
|
32
|
+
"lint": "npx xeira lint ./src",
|
|
37
33
|
"reset": "rm -fr package-lock.json npm-lock.yaml dist/* && npm i",
|
|
38
34
|
"clean": "rm -fr ./dist/*",
|
|
39
35
|
"bundle": "npx xeira bundle --target=node --source_index=./src/index.mjs --bundle_folder=./dist --bundle_name=miolo --bundle_extension=node.mjs",
|
|
40
|
-
"dist": "npm run clean && npm run bundle"
|
|
41
|
-
"test": "npx xeira test --files=./test/index.mjs"
|
|
36
|
+
"dist": "npm run clean && npm run bundle"
|
|
42
37
|
},
|
|
43
38
|
"dependencies": {
|
|
44
39
|
"@babel/plugin-proposal-decorators": "^7.28.0",
|
|
45
|
-
"@dotenvx/dotenvx": "^1.
|
|
40
|
+
"@dotenvx/dotenvx": "^1.51.1",
|
|
46
41
|
"@koa/bodyparser": "^6.0.0",
|
|
47
42
|
"@koa/cors": "^5.0.0",
|
|
48
|
-
"@koa/router": "^
|
|
49
|
-
"@maxmind/geoip2-node": "^6.
|
|
50
|
-
"@
|
|
51
|
-
"
|
|
52
|
-
"
|
|
53
|
-
"
|
|
43
|
+
"@koa/router": "^14.0.0",
|
|
44
|
+
"@maxmind/geoip2-node": "^6.2.0",
|
|
45
|
+
"@tailwindcss/vite": "^4.1.17",
|
|
46
|
+
"@vitejs/plugin-react": "^5.1.0",
|
|
47
|
+
"cacheiro": "^0.5.0-beta.4",
|
|
48
|
+
"calustra": "^1.0.0-beta.3",
|
|
49
|
+
"cron": "^4.3.4",
|
|
54
50
|
"deepmerge": "^4.3.1",
|
|
55
51
|
"diskspace": "^2.0.0",
|
|
56
52
|
"http-terminator": "^3.2.0",
|
|
57
|
-
"intre": "^
|
|
53
|
+
"intre": "^3.0.0-beta.2",
|
|
54
|
+
"is-plain-object": "^5.0.0",
|
|
55
|
+
"joi": "^18.0.1",
|
|
58
56
|
"jwt-simple": "^0.5.6",
|
|
59
|
-
"koa": "^3.
|
|
57
|
+
"koa": "^3.1.1",
|
|
60
58
|
"koa-compress": "^5.1.1",
|
|
61
59
|
"koa-connect": "^2.1.0",
|
|
62
60
|
"koa-favicon": "^2.1.0",
|
|
@@ -67,20 +65,21 @@
|
|
|
67
65
|
"koa-session": "^7.0.2",
|
|
68
66
|
"koa-socket-2": "^2.0.0",
|
|
69
67
|
"koa-static": "^5.0.0",
|
|
70
|
-
"
|
|
68
|
+
"nanoid": "^5.1.6",
|
|
69
|
+
"nodemailer": "^7.0.10",
|
|
71
70
|
"passport-local": "^1.0.0",
|
|
72
71
|
"socket.io": "^4.8.1",
|
|
73
72
|
"socket.io-client": "^4.8.1",
|
|
73
|
+
"statuses": "^2.0.2",
|
|
74
|
+
"tailwindcss": "^4.1.17",
|
|
74
75
|
"tinguir": "^0.0.7",
|
|
75
|
-
"vite": "^7.
|
|
76
|
-
"winston": "^3.
|
|
76
|
+
"vite": "^7.2.2",
|
|
77
|
+
"winston": "^3.18.3",
|
|
77
78
|
"winston-daily-rotate-file": "^5.0.0",
|
|
78
79
|
"yargs-parser": "^22.0.0"
|
|
79
80
|
},
|
|
80
81
|
"devDependencies": {
|
|
81
|
-
"
|
|
82
|
-
"node-fetch": "^3.3.2",
|
|
83
|
-
"xeira": "^1.2.3"
|
|
82
|
+
"xeira": "^2.0.0-beta.8"
|
|
84
83
|
},
|
|
85
84
|
"eslintConfig": {
|
|
86
85
|
"extends": [
|
package/{bin → src/config}/.env
RENAMED
|
@@ -2,20 +2,20 @@
|
|
|
2
2
|
# General
|
|
3
3
|
#
|
|
4
4
|
MIOLO_NAME=miolo
|
|
5
|
-
MIOLO_CONFIG=./src/server/config.mjs
|
|
6
5
|
MIOLO_INTRE_LOCALE=es
|
|
7
6
|
|
|
8
7
|
#
|
|
9
8
|
# HTTP
|
|
10
9
|
#
|
|
11
10
|
MIOLO_PORT=8001
|
|
11
|
+
MIOLO_DEV_PORT=7001
|
|
12
12
|
MIOLO_HOSTNAME=localhost
|
|
13
|
-
|
|
13
|
+
MIOLO_HOSTNAME_DOCKER=0.0.0.0
|
|
14
14
|
MIOLO_HTTP_CORS=simple # true | false | simple. For {options}, use JS
|
|
15
|
-
MIOLO_HTTP_PROXY=
|
|
15
|
+
MIOLO_HTTP_PROXY=false # true | false. For {options}, use JS
|
|
16
16
|
|
|
17
17
|
MIOLO_RATELIMIT_MAX=1000
|
|
18
|
-
MIOLO_RATELIMIT_DURATION=
|
|
18
|
+
MIOLO_RATELIMIT_DURATION=60000
|
|
19
19
|
#MIOLO_RATELIMIT_WHITELIST_IPS=
|
|
20
20
|
#MIOLO_RATELIMIT_BLACKLIST_IPS=
|
|
21
21
|
MIOLO_REQUEST_LAZY=1 # seconds to consider lazy a request
|
|
@@ -28,16 +28,20 @@ MIOLO_GEOIP_LOCAL_IPS=127.0.0.1
|
|
|
28
28
|
#
|
|
29
29
|
# Session
|
|
30
30
|
#
|
|
31
|
+
MIOLO_SESSION_KEY='miolo.sess'
|
|
31
32
|
MIOLO_SESSION_SALT=11111111-2222-3333-4444-555555555555
|
|
32
33
|
MIOLO_SESSION_SECRET=secret
|
|
33
34
|
MIOLO_SESSION_MAX_AGE=864000000
|
|
34
35
|
MIOLO_SESSION_SECURE=true
|
|
36
|
+
MIOLO_SESSION_RENEW=false
|
|
37
|
+
MIOLO_SESSION_SAME_SITE=lax # lax | strict
|
|
35
38
|
|
|
36
39
|
#
|
|
37
40
|
# Database
|
|
38
41
|
#
|
|
39
42
|
MIOLO_DB_DIALECT=postgres
|
|
40
43
|
MIOLO_DB_HOST=localhost
|
|
44
|
+
MIOLO_DB_DOCKER_HOST=postgres
|
|
41
45
|
MIOLO_DB_PORT=5432
|
|
42
46
|
MIOLO_DB_DATABASE=my_database
|
|
43
47
|
MIOLO_DB_USER=my_user
|
|
@@ -58,7 +62,7 @@ MIOLO_LOG_LEVEL=verbose
|
|
|
58
62
|
MIOLO_LOG_CONSOLE_ENABLED=true
|
|
59
63
|
#MIOLO_LOG_CONSOLE_LEVEL=verbose
|
|
60
64
|
|
|
61
|
-
MIOLO_LOG_FILE_ENABLED=
|
|
65
|
+
MIOLO_LOG_FILE_ENABLED=false
|
|
62
66
|
#MIOLO_LOG_FILE_LEVEL=verbose
|
|
63
67
|
|
|
64
68
|
MIOLO_LOG_FILE_PATH=/var/log/afialapis/%MIOLO%.log
|
|
@@ -84,6 +88,11 @@ MIOLO_MAILER_SMTP_PASS=****
|
|
|
84
88
|
#
|
|
85
89
|
# Cache
|
|
86
90
|
#
|
|
91
|
+
MIOLO_REDIS_HOSTNAME=localhost
|
|
92
|
+
MIOLO_REDIS_HOSTNAME_DOCKER=redis
|
|
93
|
+
MIOLO_REDIS_PORT=6379
|
|
94
|
+
|
|
95
|
+
MIOLO_CACHE_TYPE=combined
|
|
87
96
|
MIOLO_CACHE_VERSION=1
|
|
88
97
|
MIOLO_CACHE_CALUSTRA_VERSION=1
|
|
89
98
|
MIOLO_CACHE_CALUSTRA_TTL=86400000
|
|
@@ -101,8 +110,10 @@ MIOLO_DOTENVX_DEBUG=false
|
|
|
101
110
|
MIOLO_BUILD_HTML_FILE=./src/cli/index.html
|
|
102
111
|
MIOLO_BUILD_CLIENT_ENTRY=./src/cli/entry-cli.jsx
|
|
103
112
|
MIOLO_BUILD_CLIENT_DEST=./dist/cli
|
|
113
|
+
MIOLO_BUILD_CLIENT_SUFFIX=iife.bundle.min
|
|
104
114
|
MIOLO_BUILD_SERVER_SSR_ENTRY=./src/server/ssr/entry-server.jsx
|
|
115
|
+
MIOLO_BUILD_SERVER_ENTRY=./src/server/server.mjs
|
|
105
116
|
MIOLO_BUILD_SERVER_DEST=./dist/server
|
|
106
|
-
|
|
117
|
+
MIOLO_DEV_CONFIG_ENTRY=./src/server/config.mjs
|
|
107
118
|
MIOLO_DEV_WATCH_ENABLED=true
|
|
108
119
|
MIOLO_DEV_WATCH_DIRS=./src/server
|