@pulse-editor/cli 0.1.1-beta.20 → 0.1.1-beta.21

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.
@@ -69,15 +69,21 @@ app.all(/^\/server-function\/(.*)/, async (req, res) => {
69
69
  // eslint-disable-next-line @typescript-eslint/no-explicit-any
70
70
  const response = await loadAndCall(func, request, pulseConfig.id, 'http://localhost:3030', pulseConfig.version);
71
71
  const streamPipeline = promisify(pipeline);
72
- // If loadAndCall returns a Response (Fetch API Response)
73
- if (response.body) {
74
- // Convert WHATWG stream to Node.js stream
75
- const nodeStream = Readable.fromWeb(response.body);
76
- // Pipe it directly to Express
77
- await streamPipeline(nodeStream, res);
78
- }
79
- else {
80
- res.end();
72
+ if (response) {
73
+ // 1️⃣ Set status code
74
+ res.status(response.status);
75
+ // 2️⃣ Copy headers
76
+ response.headers.forEach((value, key) => {
77
+ res.setHeader(key, value);
78
+ });
79
+ // 3️⃣ Pipe body if present
80
+ if (response.body) {
81
+ const nodeStream = Readable.fromWeb(response.body);
82
+ await streamPipeline(nodeStream, res);
83
+ }
84
+ else {
85
+ res.end();
86
+ }
81
87
  }
82
88
  });
83
89
  if (isPreview) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@pulse-editor/cli",
3
- "version": "0.1.1-beta.20",
3
+ "version": "0.1.1-beta.21",
4
4
  "license": "MIT",
5
5
  "bin": {
6
6
  "pulse": "dist/cli.js"