@jay-framework/editor-server 0.6.3 → 0.6.5
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 +28 -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,16 @@ 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(
|
|
42
|
+
"Access-Control-Allow-Headers",
|
|
43
|
+
"Origin, X-Requested-With, Content-Type, Accept, Authorization"
|
|
44
|
+
);
|
|
45
|
+
res.setHeader("Access-Control-Allow-Credentials", "true");
|
|
28
46
|
if (!this.isLocalhost(clientIP)) {
|
|
29
47
|
console.warn(`Rejected connection from non-localhost IP: ${clientIP}`);
|
|
30
48
|
res.writeHead(403, { "Content-Type": "application/json" });
|
|
@@ -44,8 +62,9 @@ class EditorServer {
|
|
|
44
62
|
});
|
|
45
63
|
this.io = new Server(this.httpServer, {
|
|
46
64
|
cors: {
|
|
47
|
-
origin:
|
|
48
|
-
methods: ["GET", "POST"]
|
|
65
|
+
origin: ALLOWED_ORIGINS,
|
|
66
|
+
methods: ["GET", "POST"],
|
|
67
|
+
credentials: true
|
|
49
68
|
},
|
|
50
69
|
allowEIO3: true
|
|
51
70
|
});
|
|
@@ -84,15 +103,15 @@ class EditorServer {
|
|
|
84
103
|
res.end(JSON.stringify({ error: "Missing tab ID" }));
|
|
85
104
|
return;
|
|
86
105
|
}
|
|
87
|
-
if (!this.editorId) {
|
|
88
|
-
this.editorId = tabId;
|
|
89
|
-
this.onEditorId && this.onEditorId(tabId);
|
|
90
|
-
}
|
|
91
106
|
const response = {
|
|
92
|
-
status: this.editorId === tabId ? "
|
|
107
|
+
status: this.editorId === tabId ? "match" : !this.editorId ? "init" : "no-match",
|
|
93
108
|
id: this.editorId,
|
|
94
109
|
port: this.port
|
|
95
110
|
};
|
|
111
|
+
if (!this.editorId) {
|
|
112
|
+
this.editorId = tabId;
|
|
113
|
+
this.onEditorId && this.onEditorId(tabId);
|
|
114
|
+
}
|
|
96
115
|
res.writeHead(200, { "Content-Type": "application/json" });
|
|
97
116
|
res.end(JSON.stringify(response));
|
|
98
117
|
}
|
|
@@ -106,7 +125,7 @@ class EditorServer {
|
|
|
106
125
|
socket.disconnect(true);
|
|
107
126
|
return;
|
|
108
127
|
}
|
|
109
|
-
console.log(`Editor connected: ${socket.id} from ${clientIP}`);
|
|
128
|
+
console.log(`Editor Socket connected: ${socket.id} from ${clientIP}`);
|
|
110
129
|
socket.on("protocol-message", async (message) => {
|
|
111
130
|
try {
|
|
112
131
|
const response = await this.handleProtocolMessage(message);
|
|
@@ -122,7 +141,7 @@ class EditorServer {
|
|
|
122
141
|
}
|
|
123
142
|
});
|
|
124
143
|
socket.on("disconnect", () => {
|
|
125
|
-
console.log(`Editor disconnected: ${socket.id}`);
|
|
144
|
+
console.log(`Editor Socket disconnected: ${socket.id}`);
|
|
126
145
|
});
|
|
127
146
|
});
|
|
128
147
|
}
|
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.5",
|
|
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.5",
|
|
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.5",
|
|
31
|
+
"@jay-framework/editor-client": "^0.6.5",
|
|
32
|
+
"@jay-framework/jay-cli": "^0.6.5",
|
|
33
33
|
"@types/express": "^5.0.2",
|
|
34
34
|
"@types/node": "^22.15.21",
|
|
35
35
|
"@types/uuid": "^9.0.7",
|