@jay-framework/editor-server 0.6.3 → 0.6.4
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/dist/index.js +25 -9
- package/package.json +5 -5
package/dist/index.js
CHANGED
|
@@ -8,6 +8,14 @@ import { Server } from "socket.io";
|
|
|
8
8
|
import { createServer } from "http";
|
|
9
9
|
import getPort from "get-port";
|
|
10
10
|
import { createProtocolResponse } from "@jay-framework/editor-protocol";
|
|
11
|
+
const ALLOWED_ORIGINS = [
|
|
12
|
+
"https://www.figma.com",
|
|
13
|
+
"https://figma.com",
|
|
14
|
+
"http://localhost:*",
|
|
15
|
+
"http://127.0.0.1:*",
|
|
16
|
+
"null"
|
|
17
|
+
// For local development/file:// protocol
|
|
18
|
+
];
|
|
11
19
|
class EditorServer {
|
|
12
20
|
constructor(options) {
|
|
13
21
|
__publicField(this, "io", null);
|
|
@@ -25,6 +33,13 @@ class EditorServer {
|
|
|
25
33
|
this.port = await getPort({ port: this.portRange });
|
|
26
34
|
this.httpServer = createServer((req, res) => {
|
|
27
35
|
const clientIP = req.socket.remoteAddress || req.connection.remoteAddress;
|
|
36
|
+
const origin = req.headers.origin;
|
|
37
|
+
if (ALLOWED_ORIGINS.includes(origin)) {
|
|
38
|
+
res.setHeader("Access-Control-Allow-Origin", origin);
|
|
39
|
+
}
|
|
40
|
+
res.setHeader("Access-Control-Allow-Methods", "GET, POST, PUT, DELETE, OPTIONS");
|
|
41
|
+
res.setHeader("Access-Control-Allow-Headers", "Origin, X-Requested-With, Content-Type, Accept, Authorization");
|
|
42
|
+
res.setHeader("Access-Control-Allow-Credentials", "true");
|
|
28
43
|
if (!this.isLocalhost(clientIP)) {
|
|
29
44
|
console.warn(`Rejected connection from non-localhost IP: ${clientIP}`);
|
|
30
45
|
res.writeHead(403, { "Content-Type": "application/json" });
|
|
@@ -44,8 +59,9 @@ class EditorServer {
|
|
|
44
59
|
});
|
|
45
60
|
this.io = new Server(this.httpServer, {
|
|
46
61
|
cors: {
|
|
47
|
-
origin:
|
|
48
|
-
methods: ["GET", "POST"]
|
|
62
|
+
origin: ALLOWED_ORIGINS,
|
|
63
|
+
methods: ["GET", "POST"],
|
|
64
|
+
credentials: true
|
|
49
65
|
},
|
|
50
66
|
allowEIO3: true
|
|
51
67
|
});
|
|
@@ -84,15 +100,15 @@ class EditorServer {
|
|
|
84
100
|
res.end(JSON.stringify({ error: "Missing tab ID" }));
|
|
85
101
|
return;
|
|
86
102
|
}
|
|
87
|
-
if (!this.editorId) {
|
|
88
|
-
this.editorId = tabId;
|
|
89
|
-
this.onEditorId && this.onEditorId(tabId);
|
|
90
|
-
}
|
|
91
103
|
const response = {
|
|
92
|
-
status: this.editorId === tabId ? "
|
|
104
|
+
status: this.editorId === tabId ? "match" : !this.editorId ? "init" : "no-match",
|
|
93
105
|
id: this.editorId,
|
|
94
106
|
port: this.port
|
|
95
107
|
};
|
|
108
|
+
if (!this.editorId) {
|
|
109
|
+
this.editorId = tabId;
|
|
110
|
+
this.onEditorId && this.onEditorId(tabId);
|
|
111
|
+
}
|
|
96
112
|
res.writeHead(200, { "Content-Type": "application/json" });
|
|
97
113
|
res.end(JSON.stringify(response));
|
|
98
114
|
}
|
|
@@ -106,7 +122,7 @@ class EditorServer {
|
|
|
106
122
|
socket.disconnect(true);
|
|
107
123
|
return;
|
|
108
124
|
}
|
|
109
|
-
console.log(`Editor connected: ${socket.id} from ${clientIP}`);
|
|
125
|
+
console.log(`Editor Socket connected: ${socket.id} from ${clientIP}`);
|
|
110
126
|
socket.on("protocol-message", async (message) => {
|
|
111
127
|
try {
|
|
112
128
|
const response = await this.handleProtocolMessage(message);
|
|
@@ -122,7 +138,7 @@ class EditorServer {
|
|
|
122
138
|
}
|
|
123
139
|
});
|
|
124
140
|
socket.on("disconnect", () => {
|
|
125
|
-
console.log(`Editor disconnected: ${socket.id}`);
|
|
141
|
+
console.log(`Editor Socket disconnected: ${socket.id}`);
|
|
126
142
|
});
|
|
127
143
|
});
|
|
128
144
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@jay-framework/editor-server",
|
|
3
|
-
"version": "0.6.
|
|
3
|
+
"version": "0.6.4",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"license": "Apache-2.0",
|
|
6
6
|
"main": "dist/index.js",
|
|
@@ -20,16 +20,16 @@
|
|
|
20
20
|
"test:watch": "vitest"
|
|
21
21
|
},
|
|
22
22
|
"dependencies": {
|
|
23
|
-
"@jay-framework/editor-protocol": "^0.6.
|
|
23
|
+
"@jay-framework/editor-protocol": "^0.6.4",
|
|
24
24
|
"get-port": "^7.0.0",
|
|
25
25
|
"socket.io": "^4.7.4",
|
|
26
26
|
"uuid": "^9.0.1",
|
|
27
27
|
"yaml": "^2.3.4"
|
|
28
28
|
},
|
|
29
29
|
"devDependencies": {
|
|
30
|
-
"@jay-framework/dev-environment": "^0.6.
|
|
31
|
-
"@jay-framework/editor-client": "^0.6.
|
|
32
|
-
"@jay-framework/jay-cli": "^0.6.
|
|
30
|
+
"@jay-framework/dev-environment": "^0.6.4",
|
|
31
|
+
"@jay-framework/editor-client": "^0.6.4",
|
|
32
|
+
"@jay-framework/jay-cli": "^0.6.4",
|
|
33
33
|
"@types/express": "^5.0.2",
|
|
34
34
|
"@types/node": "^22.15.21",
|
|
35
35
|
"@types/uuid": "^9.0.7",
|