@wix/origami-site-express 0.1.2 → 0.1.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/README.md +2 -0
- package/package.json +2 -2
- package/src/server/dev.js +3 -3
- package/src/server/prod.js +2 -2
- package/src/server/shell.js +13 -0
package/README.md
CHANGED
|
@@ -18,3 +18,5 @@ through Vite; set `HOST=0.0.0.0` to reach it from another machine or a container
|
|
|
18
18
|
- In dev each request imports the core through Vite's module runner, so a linked core reloads on edit
|
|
19
19
|
without a restart. An installed core loads once.
|
|
20
20
|
- HMR runs on the site's own port (`server.ws.server`).
|
|
21
|
+
- The page's essential Wix custom embeds (`resolution.embeds`) go at the end of `<head>`, first in `<body>` and
|
|
22
|
+
last in `<body>`; in dev after `vite.transformIndexHtml`.
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@wix/origami-site-express",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.3",
|
|
4
4
|
"description": "Run an exported Wix origami site on Node with Express and Vite.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"files": [
|
|
@@ -65,5 +65,5 @@
|
|
|
65
65
|
]
|
|
66
66
|
}
|
|
67
67
|
},
|
|
68
|
-
"falconPackageHash": "
|
|
68
|
+
"falconPackageHash": "455a5d4751b360861bad538b9622e269cf9952063df493f85de30eb9"
|
|
69
69
|
}
|
package/src/server/dev.js
CHANGED
|
@@ -4,7 +4,7 @@ import { createServer as createViteServer, isRunnableDevEnvironment, loadEnv } f
|
|
|
4
4
|
import react from '@vitejs/plugin-react'
|
|
5
5
|
import { coreEntry, importCoreBuild, importCoreNode, importCoreServer } from './core.js'
|
|
6
6
|
import { catchAll } from './bridge.js'
|
|
7
|
-
import { pageHtml } from './shell.js'
|
|
7
|
+
import { pageHtml, plantEmbeds } from './shell.js'
|
|
8
8
|
import { host, port, siteOptions } from './env.js'
|
|
9
9
|
import { serve } from './lifecycle.js'
|
|
10
10
|
import { createCurrentSite } from './currentSite.js'
|
|
@@ -41,10 +41,10 @@ export async function dev({ root }) {
|
|
|
41
41
|
app.use(vite.middlewares)
|
|
42
42
|
app.use(catchAll({
|
|
43
43
|
mode: 'dev', errorResponse, node, getSite: currentSite,
|
|
44
|
-
renderPage: (resolution, request) => vite.transformIndexHtml(new URL(request.url).pathname, pageHtml(resolution, {
|
|
44
|
+
renderPage: async (resolution, request) => plantEmbeds(await vite.transformIndexHtml(new URL(request.url).pathname, pageHtml(resolution, {
|
|
45
45
|
serializePageData,
|
|
46
46
|
body: '<script type="module" src="/src/site/_generated/client.jsx"></script>',
|
|
47
|
-
})),
|
|
47
|
+
})), resolution.embeds),
|
|
48
48
|
}))
|
|
49
49
|
httpServer.on('request', app)
|
|
50
50
|
await serve(httpServer, { port: port(), host: host('dev'), onClose: async () => { await vite.close(); await site()?.close() } })
|
package/src/server/prod.js
CHANGED
|
@@ -4,7 +4,7 @@ import { join } from 'node:path'
|
|
|
4
4
|
import express from 'express'
|
|
5
5
|
import { importCoreNode, importCoreServer } from './core.js'
|
|
6
6
|
import { catchAll } from './bridge.js'
|
|
7
|
-
import { pageHtml } from './shell.js'
|
|
7
|
+
import { pageHtml, plantEmbeds } from './shell.js'
|
|
8
8
|
import { readManifest } from './manifest.js'
|
|
9
9
|
import { port, siteOptions } from './env.js'
|
|
10
10
|
import { serve } from './lifecycle.js'
|
|
@@ -26,7 +26,7 @@ export async function start({ root }) {
|
|
|
26
26
|
app.use(express.static(join(root, 'dist/client'), { index: false, redirect: false }))
|
|
27
27
|
app.use(catchAll({
|
|
28
28
|
mode: 'prod', errorResponse, node, getSite: async () => site,
|
|
29
|
-
renderPage: async resolution => pageHtml(resolution, { serializePageData, ...assetsFor(resolution.page) }),
|
|
29
|
+
renderPage: async resolution => plantEmbeds(pageHtml(resolution, { serializePageData, ...assetsFor(resolution.page) }), resolution.embeds),
|
|
30
30
|
}))
|
|
31
31
|
await serve(createServer(app), { port: port(), onClose: () => site.close() })
|
|
32
32
|
}
|
package/src/server/shell.js
CHANGED
|
@@ -21,3 +21,16 @@ export function pageHtml({ page, data }, { serializePageData, head = '', body })
|
|
|
21
21
|
</body>
|
|
22
22
|
</html>`
|
|
23
23
|
}
|
|
24
|
+
|
|
25
|
+
/** Plants the page's Wix embeds at the end of <head>, the start of <body> and the end of <body>. Positions are
|
|
26
|
+
* found in the shell before anything is inserted, so embed HTML can never move the next slot. In dev this runs
|
|
27
|
+
* after vite.transformIndexHtml, so Vite never rewrites an embed's inline scripts.
|
|
28
|
+
* @param {string} html @param {import('@wix/origami-site/types').PageEmbeds | undefined} embeds */
|
|
29
|
+
export function plantEmbeds(html, embeds) {
|
|
30
|
+
if (!embeds || (!embeds.head && !embeds.bodyStart && !embeds.bodyEnd)) return html
|
|
31
|
+
const headEnd = html.indexOf('</head>')
|
|
32
|
+
const bodyStart = html.indexOf('>', html.indexOf('<body')) + 1
|
|
33
|
+
const bodyEnd = html.lastIndexOf('</body>')
|
|
34
|
+
return html.slice(0, headEnd) + `${embeds.head}\n ` + html.slice(headEnd, bodyStart) + `\n${embeds.bodyStart}` +
|
|
35
|
+
html.slice(bodyStart, bodyEnd) + `${embeds.bodyEnd}\n ` + html.slice(bodyEnd)
|
|
36
|
+
}
|