miolo 3.0.0-beta.13 → 3.0.0-beta.15

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 CHANGED
@@ -12,7 +12,7 @@ MIOLO_PORT=8001
12
12
  MIOLO_HOSTNAME=localhost
13
13
 
14
14
  MIOLO_HTTP_CORS=simple # true | false | simple. For {options}, use JS
15
- MIOLO_HTTP_PROXY=true # true | false. For {options}, use JS
15
+ MIOLO_HTTP_PROXY=false # true | false. For {options}, use JS
16
16
 
17
17
  MIOLO_RATELIMIT_MAX=1000
18
18
  MIOLO_RATELIMIT_DURATION=60 * 1000
@@ -101,8 +101,8 @@ MIOLO_DOTENVX_DEBUG=false
101
101
  MIOLO_BUILD_HTML_FILE=./src/cli/index.html
102
102
  MIOLO_BUILD_CLIENT_ENTRY=./src/cli/entry-cli.jsx
103
103
  MIOLO_BUILD_CLIENT_DEST=./dist/cli
104
+ MIOLO_BUILD_CLIENT_SUFFIX=iife.bundle.min
104
105
  MIOLO_BUILD_SERVER_SSR_ENTRY=./src/server/ssr/entry-server.jsx
105
106
  MIOLO_BUILD_SERVER_DEST=./dist/server
106
- MIOLO_BUNDLE_SUFFIX=iife.bundle.min
107
107
  MIOLO_DEV_WATCH_ENABLED=true
108
108
  MIOLO_DEV_WATCH_DIRS=./src/server
@@ -3,7 +3,7 @@ import {xeiraBundle} from 'xeira'
3
3
  import { cleanFolder, copyFileSync, isFileExistingSync } from './util.mjs'
4
4
 
5
5
  function _addCssLinkToHead(appName, htmlString, dest) {
6
- const linkTag = ` <link href="${dest}/${appName}.${process.env.MIOLO_BUNDLE_SUFFIX}.css" rel="stylesheet" media="all">`
6
+ const linkTag = ` <link href="${dest}/${appName}.${process.env.MIOLO_BUILD_CLIENT_SUFFIX}.css" rel="stylesheet" media="all">`
7
7
 
8
8
  // Expresión regular para encontrar la etiqueta </head> de cierre.
9
9
  // Usamos un grupo de captura para mantener el contenido antes de </head>.
@@ -35,12 +35,12 @@ export default async function(appName, entry, htmlFile, dest) {
35
35
  target: 'browser',
36
36
  bundle_folder: dest,
37
37
  bundle_name: appName,
38
- bundle_extension: process.env.MIOLO_BUNDLE_SUFFIX,
38
+ bundle_extension: process.env.MIOLO_BUILD_CLIENT_SUFFIX,
39
39
  bundler: 'rollup',
40
40
  bundle_node_polyfill: true
41
41
  })
42
42
 
43
- const destCssFile = `${dest}/${appName}.${process.env.MIOLO_BUNDLE_SUFFIX}.css`
43
+ const destCssFile = `${dest}/${appName}.${process.env.MIOLO_BUILD_CLIENT_SUFFIX}.css`
44
44
  const destCssFileExists = isFileExistingSync(destCssFile)
45
45
 
46
46
  console.log(`[${appName}][prod] destCssFile ${destCssFile} exists?: ${destCssFileExists}`)
@@ -39,9 +39,11 @@ export default async function(appName, ssrEntry, ssrDest, dest) {
39
39
 
40
40
 
41
41
  const serverExt = 'node.bundle.mjs'
42
+ const serverIdx = process.env.MIOLO_NAME=='miolo-demo'
43
+ ? '../miolo/bin/prod_start.mjs'
44
+ : 'node_modules/miolo/bin/prod_start.mjs'
42
45
  await xeiraBundle({
43
- //source_index: 'node_modules/miolo/packages/miolo/bin/prod_start.mjs',
44
- source_index: '../miolo/bin/prod_start.mjs',
46
+ source_index: serverIdx,
45
47
  target: 'node',
46
48
  bundle_folder: dest,
47
49
  bundle_name: appName,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "miolo",
3
- "version": "3.0.0-beta.13",
3
+ "version": "3.0.0-beta.15",
4
4
  "description": "all-in-one koa-based server",
5
5
  "author": "Donato Lorenzo <donato@afialapis.com>",
6
6
  "contributors": [
@@ -439,7 +439,7 @@ export default {
439
439
  build: {
440
440
 
441
441
  client: process.env.NODE_ENV === 'production'
442
- ? `${process.env.MIOLO_BUILD_CLIENT_DEST}/${process.env.MIOLO_NAME}.${process.env.MIOLO_BUNDLE_SUFFIX}.js`
442
+ ? `${process.env.MIOLO_BUILD_CLIENT_DEST}/${process.env.MIOLO_NAME}.${process.env.MIOLO_BUILD_CLIENT_SUFFIX}.js`
443
443
  : process.env.MIOLO_BUILD_CLIENT_ENTRY,
444
444
 
445
445
  html: process.env.MIOLO_BUILD_HTML_FILE || './src/cli/index.html',
@@ -13,16 +13,10 @@ export const fallbackIndexHTML = `
13
13
  <!-- Touch Icons - iOS and Android 2.1+ 180x180 pixels in size. -->
14
14
  <!--<link rel="apple-touch-icon-precomposed" href="/favicon.ico"/>-->
15
15
  <!-- Firefox, Chrome, Safari, IE 11+ and Opera. 196x196 pixels in size. -->
16
- <link rel="icon" href="/favicon.ico"/>
17
-
18
-
19
- <script>
20
- window.__CONTEXT = {context}
21
- </script>
16
+ <link rel="icon" href="/favicon.ico"/>
22
17
  </head>
23
-
24
18
  <body>
25
- <div id="root">{children}</div>
19
+
26
20
  </body>
27
21
  </html>
28
22
  `
@@ -18,28 +18,23 @@ function _html_read(htmlFile) {
18
18
  }
19
19
  }
20
20
 
21
-
22
- function _add_client_script_to_body(htmlString, client) {
21
+ function _feed_html(htmlString, client, context, ssr_html) {
22
+ const contextScript = `<script> window.__CONTEXT = ${JSON.stringify(context, null, 2)}</script>`
23
+ const rootDiv = `<div id="root">${ssr_html}</div>`
23
24
  const linkTag =
24
25
  process.env.NODE_ENV === 'production'
25
26
  ? ` <script src="${client}" async></script>`
26
27
  : ` <script type="module" src="${client}"></script>`
27
28
 
28
- // Expresión regular para encontrar la etiqueta </body> de cierre.
29
- // Usamos un grupo de captura para mantener el contenido antes de </body>.
30
- const bodyCloseTagRegex = /(<\/body>)/i;
31
-
32
- // Busca la etiqueta </body> en el HTML.
33
- const match = htmlString.match(bodyCloseTagRegex);
34
-
35
- if (match) {
36
- // Si se encuentra </body>, inserta la etiqueta <link> justo antes de ella.
37
- return htmlString.replace(bodyCloseTagRegex, `${linkTag}\n$&`);
38
- } else {
39
- // Si no se encuentra </body>, devuelve el HTML original sin modificar.
40
- console.warn(`[miolo] No se encontró la etiqueta <body> en el HTML proporcionado.`);
41
- return htmlString;
42
- }
29
+ // head
30
+ const headCloseTagRegex = /(<\/head>)/i
31
+ htmlString= htmlString.replace(headCloseTagRegex, `${contextScript}\n$&`)
32
+
33
+ // body
34
+ const bodyCloseTagRegex = /(<\/body>)/i
35
+ htmlString= htmlString.replace(bodyCloseTagRegex, `${rootDiv}\n${linkTag}\n$&`)
36
+
37
+ return htmlString
43
38
  }
44
39
 
45
40
 
@@ -48,12 +43,7 @@ export const ssr_html_renderer_make = async (app, ssrConfig, htmlFile, client, d
48
43
  const isProduction = process.env.NODE_ENV === 'production'
49
44
 
50
45
  // check HTML
51
- let tmplHtml = _html_read(htmlFile)
52
- for (const vrb of ['{context}', '{children}']) {
53
- if (tmplHtml.indexOf(vrb) < 0) {
54
- app.context.miolo.logger.error(`[ssr] Provided HTML for rendering has no ${vrb} template variable`)
55
- }
56
- }
46
+ const tmplHtml = _html_read(htmlFile)
57
47
 
58
48
  const ssr_html_renderer = async (ctx, context) => {
59
49
  let base_html= tmplHtml
@@ -94,11 +84,7 @@ export const ssr_html_renderer_make = async (app, ssrConfig, htmlFile, client, d
94
84
  `
95
85
  }
96
86
 
97
- let parsed_html = base_html
98
- .replace('{context}', JSON.stringify(context, null, 2))
99
- .replace('{children}', ssr_html)
100
-
101
- parsed_html = _add_client_script_to_body(parsed_html, client)
87
+ const parsed_html = _feed_html(base_html, client, context, ssr_html)
102
88
 
103
89
  return parsed_html
104
90
  }