@lvce-editor/server 0.53.6 → 0.53.8
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/ThirdPartyNotices.txt +2 -2
- package/package.json +3 -3
- package/src/server.js +40 -13
package/ThirdPartyNotices.txt
CHANGED
|
@@ -2,7 +2,7 @@ This project incorporates components from the projects listed below, that may ha
|
|
|
2
2
|
differing from this project:
|
|
3
3
|
|
|
4
4
|
|
|
5
|
-
1) License Notice for static/
|
|
5
|
+
1) License Notice for static/ac6286f/icons (from https://github.com/microsoft/vscode-icons)
|
|
6
6
|
---------------------------------------
|
|
7
7
|
|
|
8
8
|
Attribution 4.0 International
|
|
@@ -402,7 +402,7 @@ public licenses.
|
|
|
402
402
|
Creative Commons may be contacted at creativecommons.org.
|
|
403
403
|
|
|
404
404
|
|
|
405
|
-
2) License Notice for static/
|
|
405
|
+
2) License Notice for static/ac6286f/fonts/FiraCode-VariableFont.ttf (from https://github.com/tonsky/FiraCode)
|
|
406
406
|
---------------------------------------
|
|
407
407
|
|
|
408
408
|
Copyright (c) 2014, The Fira Code Project Authors (https://github.com/tonsky/FiraCode)
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@lvce-editor/server",
|
|
3
|
-
"version": "0.53.
|
|
3
|
+
"version": "0.53.8",
|
|
4
4
|
"description": "Run LVCE Editor as a server.",
|
|
5
5
|
"main": "index.js",
|
|
6
6
|
"bin": "bin/server.js",
|
|
@@ -20,7 +20,7 @@
|
|
|
20
20
|
"node": ">=18"
|
|
21
21
|
},
|
|
22
22
|
"dependencies": {
|
|
23
|
-
"@lvce-editor/shared-process": "0.53.
|
|
24
|
-
"@lvce-editor/static-server": "0.53.
|
|
23
|
+
"@lvce-editor/shared-process": "0.53.8",
|
|
24
|
+
"@lvce-editor/static-server": "0.53.8"
|
|
25
25
|
}
|
|
26
26
|
}
|
package/src/server.js
CHANGED
|
@@ -46,7 +46,7 @@ const isStatic = (url) => {
|
|
|
46
46
|
if(url === '/'){
|
|
47
47
|
return true
|
|
48
48
|
}
|
|
49
|
-
if (url.startsWith('/
|
|
49
|
+
if (url.startsWith('/ac6286f')) {
|
|
50
50
|
return true
|
|
51
51
|
}
|
|
52
52
|
if (url.startsWith('/favicon.ico')) {
|
|
@@ -186,6 +186,8 @@ const getOrCreateSharedProcess = () => {
|
|
|
186
186
|
const launchStaticServerProcess = async () => {
|
|
187
187
|
const staticServerPath = fileURLToPath(import.meta.resolve('@lvce-editor/static-server'))
|
|
188
188
|
const ipc = await launchProcess(staticServerPath, ['--ipc-type=node-worker'])
|
|
189
|
+
ipc.on('message', handleMessage)
|
|
190
|
+
|
|
189
191
|
return ipc
|
|
190
192
|
}
|
|
191
193
|
|
|
@@ -222,14 +224,22 @@ const handleRequestError = (error) => {
|
|
|
222
224
|
console.info('[info]: request upgrade error', error)
|
|
223
225
|
}
|
|
224
226
|
|
|
225
|
-
const
|
|
227
|
+
const handleSocketUpgradeError = (error) => {
|
|
226
228
|
// @ts-ignore
|
|
227
229
|
console.info('[info] request socket upgrade error', error)
|
|
228
230
|
}
|
|
229
231
|
|
|
232
|
+
const handleSocketError = (error) => {
|
|
233
|
+
if (error && error.code === 'ECONNRESET') {
|
|
234
|
+
return
|
|
235
|
+
}
|
|
236
|
+
// @ts-ignore
|
|
237
|
+
console.info('[info] request socket error', error)
|
|
238
|
+
}
|
|
239
|
+
|
|
230
240
|
const sendHandleSharedProcess = async (request, socket, method, ...params) => {
|
|
231
241
|
request.on('error', handleRequestError)
|
|
232
|
-
socket.on('error',
|
|
242
|
+
socket.on('error', handleSocketUpgradeError)
|
|
233
243
|
const sharedProcess = await getOrCreateSharedProcess()
|
|
234
244
|
sharedProcess.send(
|
|
235
245
|
{
|
|
@@ -256,19 +266,36 @@ const setHeaders = (response, headers) => {
|
|
|
256
266
|
}
|
|
257
267
|
}
|
|
258
268
|
|
|
269
|
+
const callbacks = Object.create(null)
|
|
270
|
+
|
|
271
|
+
const registerCallback = () => {
|
|
272
|
+
const id = createId()
|
|
273
|
+
const { resolve, promise } = Promise.withResolvers()
|
|
274
|
+
callbacks[id] = resolve
|
|
275
|
+
return {
|
|
276
|
+
id,
|
|
277
|
+
promise,
|
|
278
|
+
}
|
|
279
|
+
}
|
|
280
|
+
|
|
281
|
+
const handleMessage = (message) => {
|
|
282
|
+
const { id } = message
|
|
283
|
+
if (callbacks[id]) {
|
|
284
|
+
callbacks[id](message)
|
|
285
|
+
delete callbacks[id]
|
|
286
|
+
}
|
|
287
|
+
}
|
|
288
|
+
|
|
289
|
+
const hasErrorListener = new WeakSet()
|
|
290
|
+
|
|
259
291
|
const sendHandleStaticServerProcess = async (request, res, method, ...params) => {
|
|
260
292
|
request.on('error', handleRequestError)
|
|
261
|
-
res.socket
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
const id = createId()
|
|
265
|
-
const handleMessage = (message) => {
|
|
266
|
-
if (message.id && message.id === id) {
|
|
267
|
-
resolve(message)
|
|
268
|
-
staticServerProcess.off('message', handleMessage)
|
|
269
|
-
}
|
|
293
|
+
if (!hasErrorListener.has(res.socket)) {
|
|
294
|
+
res.socket.on('error', handleSocketError)
|
|
295
|
+
hasErrorListener.add(res.socket)
|
|
270
296
|
}
|
|
271
|
-
staticServerProcess
|
|
297
|
+
const staticServerProcess = await getOrCreateStaticServerPathProcess()
|
|
298
|
+
const { id, promise } = registerCallback()
|
|
272
299
|
staticServerProcess.send({
|
|
273
300
|
jsonrpc: '2.0',
|
|
274
301
|
id,
|