@live-change/server 0.9.119 → 0.9.121
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/lib/Renderer.js +40 -14
- package/package.json +7 -7
package/lib/Renderer.js
CHANGED
|
@@ -4,6 +4,8 @@ import * as vite from 'vite'
|
|
|
4
4
|
import serialize from 'serialize-javascript'
|
|
5
5
|
import renderTemplate from './renderTemplate.js'
|
|
6
6
|
import { SitemapStream } from 'sitemap'
|
|
7
|
+
import vm from 'vm'
|
|
8
|
+
import { createRequire } from 'module'
|
|
7
9
|
|
|
8
10
|
class Renderer {
|
|
9
11
|
constructor(manifest, settings) {
|
|
@@ -16,10 +18,17 @@ class Renderer {
|
|
|
16
18
|
if(this.settings.dev) {
|
|
17
19
|
await this.setupVite()
|
|
18
20
|
} else {
|
|
19
|
-
const serverEntryPath = path.resolve(this.root, this.settings.serverEntry ?? './dist/server/
|
|
20
|
-
|
|
21
|
-
this.
|
|
22
|
-
|
|
21
|
+
const serverEntryPath = path.resolve(this.root, this.settings.serverEntry ?? './dist/server/server.cjs')
|
|
22
|
+
const serverEntryCode = await fs.promises.readFile(serverEntryPath, { encoding: 'utf-8' })
|
|
23
|
+
this.script = new vm.Script(serverEntryCode, {
|
|
24
|
+
filename: serverEntryPath,
|
|
25
|
+
lineOffset: 0,
|
|
26
|
+
columnOffset: 0
|
|
27
|
+
})
|
|
28
|
+
this.baseContext = {
|
|
29
|
+
require: createRequire(serverEntryPath),
|
|
30
|
+
__dirname: path.dirname(serverEntryPath),
|
|
31
|
+
}
|
|
23
32
|
const templatePath = path.resolve(this.root, this.settings.templatePath ?? './dist/client/index.html')
|
|
24
33
|
this.template = await fs.promises.readFile(templatePath, { encoding: 'utf-8' })
|
|
25
34
|
}
|
|
@@ -44,7 +53,7 @@ class Renderer {
|
|
|
44
53
|
}
|
|
45
54
|
|
|
46
55
|
async renderPage(params) {
|
|
47
|
-
const { url, headers, dao, clientIp, credentials, windowId, version, now, domain } = params
|
|
56
|
+
const { url, headers, dao, clientIp, credentials, windowId, version, now, domain } = params
|
|
48
57
|
|
|
49
58
|
const render = await this.getRenderFunction()
|
|
50
59
|
const { html: appHtml, modules, data, meta, response } = await render(params)
|
|
@@ -53,13 +62,6 @@ class Renderer {
|
|
|
53
62
|
|
|
54
63
|
const preloadLinks = this.renderPreloadLinks(modules)
|
|
55
64
|
|
|
56
|
-
for(const [path, value] of data) {
|
|
57
|
-
if(path !== '{"paths":[{"what":["accessControl","objectOwnedAccessInvitations",{"object":"[Wf1KCKj1w.0@BCriY]","objectType":"speedDating_Event"}],"more":[{"schema":[["userIdentification","identification",{"object":{"sessionOrUserType":{"property":"contactOrUserType"},"sessionOrUser":{"property":"contactOrUser"}}}]],"to":"identification"}]}]}')
|
|
58
|
-
continue
|
|
59
|
-
console.log("SERIALIZE DATA", path, value[0])
|
|
60
|
-
console.log("SERIALIZED", serialize(value[0], { isJSON: true }))
|
|
61
|
-
}
|
|
62
|
-
|
|
63
65
|
const appDataScript = ` <script>` +
|
|
64
66
|
` window.__DAO_CACHE__= ${serialize(data, { isJSON: true })}\n`+
|
|
65
67
|
(this.settings.fastAuth ? ''
|
|
@@ -125,13 +127,36 @@ class Renderer {
|
|
|
125
127
|
return template
|
|
126
128
|
}
|
|
127
129
|
|
|
130
|
+
async createRenderContext() {
|
|
131
|
+
const contextObject = {
|
|
132
|
+
//...globalThis,
|
|
133
|
+
...this.baseContext,
|
|
134
|
+
exports: {},
|
|
135
|
+
//process: process,
|
|
136
|
+
process: {
|
|
137
|
+
env: {
|
|
138
|
+
NODE_ENV: 'production'
|
|
139
|
+
},
|
|
140
|
+
stdout: process.stdout,
|
|
141
|
+
stderr: process.stderr,
|
|
142
|
+
}
|
|
143
|
+
}
|
|
144
|
+
const requestContext = vm.createContext(contextObject, {
|
|
145
|
+
name: 'SSR Render '+(new Date().toISOString()),
|
|
146
|
+
///microtaskMode: 'afterEvaluate'
|
|
147
|
+
})
|
|
148
|
+
this.script.runInContext(requestContext)
|
|
149
|
+
return contextObject
|
|
150
|
+
}
|
|
151
|
+
|
|
128
152
|
async getRenderFunction() {
|
|
129
153
|
if(this.settings.dev) {
|
|
130
154
|
/// Reload every request
|
|
131
155
|
const entryPath = path.resolve(this.root, this.settings.serverEntry || 'src/entry-server.js')
|
|
132
156
|
return (await this.vite.ssrLoadModule(entryPath)).render
|
|
133
157
|
} else {
|
|
134
|
-
|
|
158
|
+
const context = await this.createRenderContext()
|
|
159
|
+
return context.exports.render
|
|
135
160
|
}
|
|
136
161
|
}
|
|
137
162
|
|
|
@@ -141,7 +166,8 @@ class Renderer {
|
|
|
141
166
|
const entryPath = path.resolve(this.root, this.settings.serverEntry || 'src/entry-server.js')
|
|
142
167
|
return (await this.vite.ssrLoadModule(entryPath)).sitemap
|
|
143
168
|
} else {
|
|
144
|
-
|
|
169
|
+
const context = await this.createRenderContext()
|
|
170
|
+
return context.exports.sitemap
|
|
145
171
|
}
|
|
146
172
|
}
|
|
147
173
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@live-change/server",
|
|
3
|
-
"version": "0.9.
|
|
3
|
+
"version": "0.9.121",
|
|
4
4
|
"description": "Live Change Framework - server",
|
|
5
5
|
"main": "index.js",
|
|
6
6
|
"scripts": {
|
|
@@ -22,12 +22,12 @@
|
|
|
22
22
|
"type": "module",
|
|
23
23
|
"homepage": "https://github.com/live-change/live-change-stack",
|
|
24
24
|
"dependencies": {
|
|
25
|
-
"@live-change/dao": "^0.9.
|
|
26
|
-
"@live-change/dao-sockjs": "^0.9.
|
|
27
|
-
"@live-change/db-server": "^0.9.
|
|
28
|
-
"@live-change/framework": "^0.9.
|
|
25
|
+
"@live-change/dao": "^0.9.121",
|
|
26
|
+
"@live-change/dao-sockjs": "^0.9.121",
|
|
27
|
+
"@live-change/db-server": "^0.9.121",
|
|
28
|
+
"@live-change/framework": "^0.9.121",
|
|
29
29
|
"@live-change/sockjs": "0.4.1",
|
|
30
|
-
"@live-change/uid": "^0.9.
|
|
30
|
+
"@live-change/uid": "^0.9.121",
|
|
31
31
|
"dotenv": "^17.2.1",
|
|
32
32
|
"express": "^4.18.2",
|
|
33
33
|
"express-static-gzip": "2.1.7",
|
|
@@ -39,5 +39,5 @@
|
|
|
39
39
|
"websocket": "^1.0.34",
|
|
40
40
|
"yargs": "^17.7.2"
|
|
41
41
|
},
|
|
42
|
-
"gitHead": "
|
|
42
|
+
"gitHead": "4052c94c9fcd898af1ed1ef7d497e2fc807b5cb0"
|
|
43
43
|
}
|