@live-change/server 0.9.137 → 0.9.139
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/index.js +3 -0
- package/lib/Renderer.js +2 -1
- package/lib/SsrServer.js +31 -3
- package/package.json +7 -7
- package/LICENSE.md +0 -11
package/index.js
CHANGED
|
@@ -13,6 +13,8 @@ import setupDbServer from './lib/setupDbServer.js'
|
|
|
13
13
|
import setupDbClient from './lib/setupDbClient.js'
|
|
14
14
|
import setupApp from './lib/setupApp.js'
|
|
15
15
|
|
|
16
|
+
import serverDao from './lib/serverDao.js'
|
|
17
|
+
|
|
16
18
|
export {
|
|
17
19
|
Renderer,
|
|
18
20
|
Services,
|
|
@@ -20,6 +22,7 @@ export {
|
|
|
20
22
|
TestServer,
|
|
21
23
|
|
|
22
24
|
createLoopbackDao,
|
|
25
|
+
serverDao,
|
|
23
26
|
renderTemplate,
|
|
24
27
|
setupApiServer,
|
|
25
28
|
setupApiSockJs,
|
package/lib/Renderer.js
CHANGED
|
@@ -152,7 +152,7 @@ class Renderer {
|
|
|
152
152
|
|
|
153
153
|
try {
|
|
154
154
|
// Use withContext only for the actual rendering part
|
|
155
|
-
const { html: appHtml, modules, data, meta, response } = await this.withContext(async (context) => {
|
|
155
|
+
const { html: appHtml, modules, data, meta, response, staticHtml } = await this.withContext(async (context) => {
|
|
156
156
|
const render = await this.getRenderFunction(context)
|
|
157
157
|
return await render(params)
|
|
158
158
|
})
|
|
@@ -168,6 +168,7 @@ class Renderer {
|
|
|
168
168
|
` window.__VERSION__ = ${serialize(version, { isJSON: true })}\n`+
|
|
169
169
|
` window.__WINDOW_ID__ = ${serialize(windowId, { isJSON: true })}\n`+
|
|
170
170
|
` window.__NOW__ = ${serialize(now, { isJSON: true })}\n`+
|
|
171
|
+
` window.__STATIC__ = ${serialize(this.settings.staticHtml || staticHtml, { isJSON: true })}\n`+
|
|
171
172
|
` console.info("SOFTWARE VERSION:" + window.__VERSION__)\n`+
|
|
172
173
|
`</script>\n`
|
|
173
174
|
|
package/lib/SsrServer.js
CHANGED
|
@@ -2,6 +2,7 @@ import cookie from 'cookie'
|
|
|
2
2
|
import path from 'path'
|
|
3
3
|
import crypto from 'crypto'
|
|
4
4
|
import os from 'os'
|
|
5
|
+
import fs from 'fs'
|
|
5
6
|
import expressStaticGzip from "express-static-gzip"
|
|
6
7
|
|
|
7
8
|
import serverDao from './serverDao.js'
|
|
@@ -54,6 +55,9 @@ class SsrServer {
|
|
|
54
55
|
}],
|
|
55
56
|
orderPreference: ['br', 'gzip', 'deflate']
|
|
56
57
|
}))
|
|
58
|
+
const prerenderPath = path.resolve(this.root, 'dist/prerender')
|
|
59
|
+
this.usePrerender = await (fs.promises.access(prerenderPath, fs.constants.F_OK).then(() => prerenderPath).catch(() => false))
|
|
60
|
+
console.log("USE PRERENDER DIRECTORY", this.usePrerender)
|
|
57
61
|
//this.express.use(serveStatic(staticPath, { index: false }))
|
|
58
62
|
}
|
|
59
63
|
|
|
@@ -111,15 +115,15 @@ class SsrServer {
|
|
|
111
115
|
const clientIp = getIp(req)
|
|
112
116
|
const credentials = readCredentials(req)
|
|
113
117
|
const windowId = this.uidGenerator()
|
|
114
|
-
const now = Date.now()
|
|
118
|
+
const now = Date.now()
|
|
115
119
|
|
|
116
120
|
try {
|
|
117
121
|
const dao = await this.createDao({ sessionKey: 'sitemap' }, clientIp)
|
|
118
122
|
try {
|
|
119
123
|
const version = this.version
|
|
124
|
+
const domain = this.settings.services?.clientConfig?.domain ?? process.env.BRAND_DOMAIN ?? 'localhost:8001'
|
|
120
125
|
await this.renderer.renderSitemap({
|
|
121
|
-
url, headers: req.headers, dao, clientIp, credentials, windowId, version, now,
|
|
122
|
-
domain: domain ?? req.headers.host
|
|
126
|
+
url, headers: req.headers, dao, clientIp, credentials, windowId, version, now, domain
|
|
123
127
|
}, res)
|
|
124
128
|
} catch (e) {
|
|
125
129
|
console.error("SITEMAP RENDERING ERROR", e.stack || e)
|
|
@@ -132,6 +136,30 @@ class SsrServer {
|
|
|
132
136
|
}
|
|
133
137
|
})
|
|
134
138
|
this.express.use('*', async (req, res) => {
|
|
139
|
+
|
|
140
|
+
if(this.usePrerender) {
|
|
141
|
+
const startTime = Date.now()
|
|
142
|
+
const baseFilename = path.resolve(this.usePrerender, req.originalUrl.slice(1) + (req.originalUrl.endsWith('/') ? 'index' : '/index'))
|
|
143
|
+
const htmlFilename = baseFilename + '.html'
|
|
144
|
+
const jsonFilename = baseFilename + '.json'
|
|
145
|
+
const exists = await fs.promises.access(htmlFilename, fs.constants.F_OK).then(() => true).catch(() => false)
|
|
146
|
+
if(exists) {
|
|
147
|
+
console.log("SERVE PRERENDERED PAGE", req.originalUrl)
|
|
148
|
+
try {
|
|
149
|
+
const html = await fs.promises.readFile(htmlFilename, { encoding: 'utf-8' })
|
|
150
|
+
const metadata = await JSON.parse(await fs.promises.readFile(jsonFilename, { encoding: 'utf-8' }))
|
|
151
|
+
res.status(200)
|
|
152
|
+
res.set(metadata?.headers ?? {
|
|
153
|
+
'Content-Type': 'text/html'
|
|
154
|
+
})
|
|
155
|
+
res.end(html)
|
|
156
|
+
console.log("SERVED PRERENDERED PAGE", req.originalUrl, 'IN', Date.now() - startTime, 'ms')
|
|
157
|
+
return
|
|
158
|
+
} catch(e) {
|
|
159
|
+
console.error("PRERENDERED PAGE ERROR", e.stack || e)
|
|
160
|
+
}
|
|
161
|
+
}
|
|
162
|
+
}
|
|
135
163
|
console.log("RENDERING PAGE", req.originalUrl)
|
|
136
164
|
if(fbRedirect(req, res)) return
|
|
137
165
|
if(this.settings.spa) {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@live-change/server",
|
|
3
|
-
"version": "0.9.
|
|
3
|
+
"version": "0.9.139",
|
|
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.139",
|
|
26
|
+
"@live-change/dao-sockjs": "^0.9.139",
|
|
27
|
+
"@live-change/db-server": "^0.9.139",
|
|
28
|
+
"@live-change/framework": "^0.9.139",
|
|
29
29
|
"@live-change/sockjs": "0.4.1",
|
|
30
|
-
"@live-change/uid": "^0.9.
|
|
30
|
+
"@live-change/uid": "^0.9.139",
|
|
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": "9202c36abc25e3baf5fe39806d89c3fab203f428"
|
|
43
43
|
}
|
package/LICENSE.md
DELETED
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
Copyright 2019-2024 Michał Łaszczewski
|
|
2
|
-
|
|
3
|
-
Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
|
|
4
|
-
|
|
5
|
-
1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
|
|
6
|
-
|
|
7
|
-
2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
|
|
8
|
-
|
|
9
|
-
3. Neither the name of the copyright holder nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission.
|
|
10
|
-
|
|
11
|
-
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|