sst 2.21.2 → 2.21.3
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/cli/local/server.js +58 -2
- package/package.json +1 -1
- package/sst.mjs +58 -2
package/cli/local/server.js
CHANGED
|
@@ -101,7 +101,15 @@ export async function useLocalServer(opts) {
|
|
|
101
101
|
return http.createServer({}, rest);
|
|
102
102
|
})();
|
|
103
103
|
// Wire up websocket
|
|
104
|
-
const wss = new WebSocketServer({
|
|
104
|
+
const wss = new WebSocketServer({ noServer: true });
|
|
105
|
+
const wss2 = new WebSocketServer({ noServer: true });
|
|
106
|
+
const sockets = new Set();
|
|
107
|
+
wss2.on("connection", (socket, req) => {
|
|
108
|
+
sockets.add(socket);
|
|
109
|
+
socket.on("close", () => {
|
|
110
|
+
sockets.delete(socket);
|
|
111
|
+
});
|
|
112
|
+
});
|
|
105
113
|
wss.on("connection", (socket, req) => {
|
|
106
114
|
if (req.headers.origin?.endsWith("localhost:3000"))
|
|
107
115
|
return;
|
|
@@ -116,6 +124,21 @@ export async function useLocalServer(opts) {
|
|
|
116
124
|
console.log("Rejecting unauthorized connection from " + req.headers.origin);
|
|
117
125
|
socket.terminate();
|
|
118
126
|
});
|
|
127
|
+
server.on("upgrade", (req, socket, head) => {
|
|
128
|
+
if (req.url === "/socket") {
|
|
129
|
+
wss2.handleUpgrade(req, socket, head, (socket) => {
|
|
130
|
+
wss2.emit("connection", socket, req);
|
|
131
|
+
});
|
|
132
|
+
return;
|
|
133
|
+
}
|
|
134
|
+
if (req.url === "/") {
|
|
135
|
+
wss.handleUpgrade(req, socket, head, (socket) => {
|
|
136
|
+
wss.emit("connection", socket, req);
|
|
137
|
+
});
|
|
138
|
+
return;
|
|
139
|
+
}
|
|
140
|
+
socket.destroy();
|
|
141
|
+
});
|
|
119
142
|
server.listen(cfg.port);
|
|
120
143
|
const handler = applyWSSHandler({
|
|
121
144
|
wss,
|
|
@@ -156,7 +179,23 @@ export async function useLocalServer(opts) {
|
|
|
156
179
|
cb(func);
|
|
157
180
|
});
|
|
158
181
|
}
|
|
159
|
-
|
|
182
|
+
function publish(type, properties) {
|
|
183
|
+
const msg = JSON.stringify({
|
|
184
|
+
type,
|
|
185
|
+
properties,
|
|
186
|
+
});
|
|
187
|
+
[...sockets.values()].map((s) => s.send(msg));
|
|
188
|
+
}
|
|
189
|
+
bus.subscribe("function.invoked", async (evt) => {
|
|
190
|
+
publish("log", [
|
|
191
|
+
[
|
|
192
|
+
"s",
|
|
193
|
+
Date.now(),
|
|
194
|
+
evt.properties.functionID,
|
|
195
|
+
evt.properties.requestID,
|
|
196
|
+
false,
|
|
197
|
+
],
|
|
198
|
+
]);
|
|
160
199
|
updateFunction(evt.properties.functionID, (draft) => {
|
|
161
200
|
if (draft.invocations.length >= 25)
|
|
162
201
|
draft.invocations.pop();
|
|
@@ -171,6 +210,17 @@ export async function useLocalServer(opts) {
|
|
|
171
210
|
});
|
|
172
211
|
});
|
|
173
212
|
bus.subscribe("worker.stdout", (evt) => {
|
|
213
|
+
publish("log", [
|
|
214
|
+
[
|
|
215
|
+
"m",
|
|
216
|
+
Date.now(),
|
|
217
|
+
evt.properties.functionID,
|
|
218
|
+
evt.properties.requestID,
|
|
219
|
+
"info",
|
|
220
|
+
evt.properties.message,
|
|
221
|
+
Math.random().toString(),
|
|
222
|
+
],
|
|
223
|
+
]);
|
|
174
224
|
updateFunction(evt.properties.functionID, (draft) => {
|
|
175
225
|
const entry = draft.invocations.find((i) => i.id === evt.properties.requestID);
|
|
176
226
|
if (!entry)
|
|
@@ -182,6 +232,9 @@ export async function useLocalServer(opts) {
|
|
|
182
232
|
});
|
|
183
233
|
});
|
|
184
234
|
bus.subscribe("function.success", (evt) => {
|
|
235
|
+
publish("log", [
|
|
236
|
+
["e", Date.now(), evt.properties.functionID, evt.properties.requestID],
|
|
237
|
+
]);
|
|
185
238
|
updateFunction(evt.properties.functionID, (draft) => {
|
|
186
239
|
const invocation = draft.invocations.find((x) => x.id === evt.properties.requestID);
|
|
187
240
|
if (!invocation)
|
|
@@ -194,6 +247,9 @@ export async function useLocalServer(opts) {
|
|
|
194
247
|
});
|
|
195
248
|
});
|
|
196
249
|
bus.subscribe("function.error", (evt) => {
|
|
250
|
+
publish("log", [
|
|
251
|
+
["e", Date.now(), evt.properties.functionID, evt.properties.requestID],
|
|
252
|
+
]);
|
|
197
253
|
updateFunction(evt.properties.functionID, (draft) => {
|
|
198
254
|
const invocation = draft.invocations.find((x) => x.id === evt.properties.requestID);
|
|
199
255
|
if (!invocation)
|
package/package.json
CHANGED
package/sst.mjs
CHANGED
|
@@ -7081,7 +7081,15 @@ async function useLocalServer(opts) {
|
|
|
7081
7081
|
}
|
|
7082
7082
|
return http2.createServer({}, rest);
|
|
7083
7083
|
})();
|
|
7084
|
-
const wss = new WebSocketServer({
|
|
7084
|
+
const wss = new WebSocketServer({ noServer: true });
|
|
7085
|
+
const wss2 = new WebSocketServer({ noServer: true });
|
|
7086
|
+
const sockets = /* @__PURE__ */ new Set();
|
|
7087
|
+
wss2.on("connection", (socket, req) => {
|
|
7088
|
+
sockets.add(socket);
|
|
7089
|
+
socket.on("close", () => {
|
|
7090
|
+
sockets.delete(socket);
|
|
7091
|
+
});
|
|
7092
|
+
});
|
|
7085
7093
|
wss.on("connection", (socket, req) => {
|
|
7086
7094
|
if (req.headers.origin?.endsWith("localhost:3000"))
|
|
7087
7095
|
return;
|
|
@@ -7096,6 +7104,21 @@ async function useLocalServer(opts) {
|
|
|
7096
7104
|
console.log("Rejecting unauthorized connection from " + req.headers.origin);
|
|
7097
7105
|
socket.terminate();
|
|
7098
7106
|
});
|
|
7107
|
+
server.on("upgrade", (req, socket, head) => {
|
|
7108
|
+
if (req.url === "/socket") {
|
|
7109
|
+
wss2.handleUpgrade(req, socket, head, (socket2) => {
|
|
7110
|
+
wss2.emit("connection", socket2, req);
|
|
7111
|
+
});
|
|
7112
|
+
return;
|
|
7113
|
+
}
|
|
7114
|
+
if (req.url === "/") {
|
|
7115
|
+
wss.handleUpgrade(req, socket, head, (socket2) => {
|
|
7116
|
+
wss.emit("connection", socket2, req);
|
|
7117
|
+
});
|
|
7118
|
+
return;
|
|
7119
|
+
}
|
|
7120
|
+
socket.destroy();
|
|
7121
|
+
});
|
|
7099
7122
|
server.listen(cfg.port);
|
|
7100
7123
|
const handler = applyWSSHandler({
|
|
7101
7124
|
wss,
|
|
@@ -7136,7 +7159,23 @@ async function useLocalServer(opts) {
|
|
|
7136
7159
|
cb(func);
|
|
7137
7160
|
});
|
|
7138
7161
|
}
|
|
7139
|
-
|
|
7162
|
+
function publish(type, properties) {
|
|
7163
|
+
const msg = JSON.stringify({
|
|
7164
|
+
type,
|
|
7165
|
+
properties
|
|
7166
|
+
});
|
|
7167
|
+
[...sockets.values()].map((s) => s.send(msg));
|
|
7168
|
+
}
|
|
7169
|
+
bus.subscribe("function.invoked", async (evt) => {
|
|
7170
|
+
publish("log", [
|
|
7171
|
+
[
|
|
7172
|
+
"s",
|
|
7173
|
+
Date.now(),
|
|
7174
|
+
evt.properties.functionID,
|
|
7175
|
+
evt.properties.requestID,
|
|
7176
|
+
false
|
|
7177
|
+
]
|
|
7178
|
+
]);
|
|
7140
7179
|
updateFunction(evt.properties.functionID, (draft) => {
|
|
7141
7180
|
if (draft.invocations.length >= 25)
|
|
7142
7181
|
draft.invocations.pop();
|
|
@@ -7151,6 +7190,17 @@ async function useLocalServer(opts) {
|
|
|
7151
7190
|
});
|
|
7152
7191
|
});
|
|
7153
7192
|
bus.subscribe("worker.stdout", (evt) => {
|
|
7193
|
+
publish("log", [
|
|
7194
|
+
[
|
|
7195
|
+
"m",
|
|
7196
|
+
Date.now(),
|
|
7197
|
+
evt.properties.functionID,
|
|
7198
|
+
evt.properties.requestID,
|
|
7199
|
+
"info",
|
|
7200
|
+
evt.properties.message,
|
|
7201
|
+
Math.random().toString()
|
|
7202
|
+
]
|
|
7203
|
+
]);
|
|
7154
7204
|
updateFunction(evt.properties.functionID, (draft) => {
|
|
7155
7205
|
const entry = draft.invocations.find(
|
|
7156
7206
|
(i) => i.id === evt.properties.requestID
|
|
@@ -7164,6 +7214,9 @@ async function useLocalServer(opts) {
|
|
|
7164
7214
|
});
|
|
7165
7215
|
});
|
|
7166
7216
|
bus.subscribe("function.success", (evt) => {
|
|
7217
|
+
publish("log", [
|
|
7218
|
+
["e", Date.now(), evt.properties.functionID, evt.properties.requestID]
|
|
7219
|
+
]);
|
|
7167
7220
|
updateFunction(evt.properties.functionID, (draft) => {
|
|
7168
7221
|
const invocation = draft.invocations.find(
|
|
7169
7222
|
(x) => x.id === evt.properties.requestID
|
|
@@ -7178,6 +7231,9 @@ async function useLocalServer(opts) {
|
|
|
7178
7231
|
});
|
|
7179
7232
|
});
|
|
7180
7233
|
bus.subscribe("function.error", (evt) => {
|
|
7234
|
+
publish("log", [
|
|
7235
|
+
["e", Date.now(), evt.properties.functionID, evt.properties.requestID]
|
|
7236
|
+
]);
|
|
7181
7237
|
updateFunction(evt.properties.functionID, (draft) => {
|
|
7182
7238
|
const invocation = draft.invocations.find(
|
|
7183
7239
|
(x) => x.id === evt.properties.requestID
|