@pulse-editor/cli 0.1.7 → 0.1.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.
|
@@ -71,31 +71,36 @@ app.all(/^\/server-function\/(.*)/, async (req, res) => {
|
|
|
71
71
|
const price = await loadPrice(func, pulseConfig.id, "http://localhost:3030", pulseConfig.version);
|
|
72
72
|
if (price) {
|
|
73
73
|
// Make func name and price bold in console
|
|
74
|
-
console.log(`🏃 Running function \x1b[1m${func}\x1b[0m, credits consumed: \x1b[1m${price}\x1b[0m`);
|
|
74
|
+
console.log(`🏃 Running server function \x1b[1m${func}\x1b[0m, credits consumed: \x1b[1m${price}\x1b[0m`);
|
|
75
75
|
}
|
|
76
76
|
else {
|
|
77
|
-
console.log(`🏃 Running function \x1b[1m${func}\x1b[0m.`);
|
|
77
|
+
console.log(`🏃 Running server function \x1b[1m${func}\x1b[0m.`);
|
|
78
78
|
}
|
|
79
79
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
80
80
|
const loadedFunc = await loadFunc(func, pulseConfig.id, "http://localhost:3030", pulseConfig.version);
|
|
81
|
-
const
|
|
81
|
+
const funcResult = await loadedFunc(request);
|
|
82
82
|
const streamPipeline = promisify(pipeline);
|
|
83
|
-
if (
|
|
83
|
+
if (funcResult) {
|
|
84
84
|
// 1️⃣ Set status code
|
|
85
|
-
res.status(
|
|
85
|
+
res.status(funcResult.status);
|
|
86
|
+
console.log(`✅ Server function "${func}" completed with status ${funcResult.status}.`);
|
|
86
87
|
// 2️⃣ Copy headers
|
|
87
|
-
|
|
88
|
+
funcResult.headers.forEach((value, key) => {
|
|
88
89
|
res.setHeader(key, value);
|
|
89
90
|
});
|
|
90
91
|
// 3️⃣ Pipe body if present
|
|
91
|
-
if (
|
|
92
|
-
const nodeStream = Readable.fromWeb(
|
|
92
|
+
if (funcResult.body) {
|
|
93
|
+
const nodeStream = Readable.fromWeb(funcResult.body);
|
|
93
94
|
await streamPipeline(nodeStream, res);
|
|
94
95
|
}
|
|
95
96
|
else {
|
|
96
97
|
res.end();
|
|
97
98
|
}
|
|
98
99
|
}
|
|
100
|
+
else {
|
|
101
|
+
console.log(`✅ Server function "${func}" completed with no content.`);
|
|
102
|
+
res.status(204).end();
|
|
103
|
+
}
|
|
99
104
|
});
|
|
100
105
|
if (isPreview) {
|
|
101
106
|
/* Preview mode */
|
|
Binary file
|