wirejs-deploy-amplify-basic 0.1.168 → 0.1.169

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.
@@ -1,4 +1,5 @@
1
1
  import http from 'http';
2
+ import https from 'https';
2
3
  import fs from 'fs';
3
4
  import path from 'path';
4
5
 
@@ -311,25 +312,54 @@ async function proxyRequest(context, res, targetUrl) {
311
312
  const body = context.requestBody;
312
313
 
313
314
  try {
314
- const response = await fetch(targetUrl, { method, headers, body });
315
- const responseBody = await response.text();
316
- const responseHeaders = response.headers;
317
-
318
- res.statusCode = response.status;
319
-
320
- [...responseHeaders.keys()].forEach((header) => {
321
- if (header === 'x-wirejs-redirect') {
322
- res.setHeader('Location', responseHeaders.get(header));
323
- } else {
324
- res.setHeader(header, responseHeaders.get(header));
325
- }
326
- });
315
+ const parsedUrl = new URL(targetUrl);
316
+ const isHttps = parsedUrl.protocol === 'https:';
317
+ const requester = isHttps ? https : http;
318
+
319
+ return await new Promise((resolve) => {
320
+ const req = requester.request({
321
+ hostname: parsedUrl.hostname,
322
+ port: parsedUrl.port || (isHttps ? 443 : 80),
323
+ path: parsedUrl.pathname + (parsedUrl.search || ''),
324
+ method,
325
+ headers,
326
+ }, (proxyRes) => {
327
+ res.statusCode = proxyRes.statusCode;
328
+
329
+ for (const [header, value] of Object.entries(proxyRes.headers)) {
330
+ if (header === 'x-wirejs-redirect') {
331
+ res.setHeader('Location', value);
332
+ } else {
333
+ res.setHeader(header, value);
334
+ }
335
+ }
327
336
 
328
- res.end(responseBody);
337
+ const chunks = [];
338
+ proxyRes.on('data', chunk => chunks.push(chunk));
339
+ proxyRes.on('end', () => {
340
+ res.end(Buffer.concat(chunks));
341
+ resolve(true);
342
+ });
343
+ });
344
+
345
+ req.on('error', (error) => {
346
+ logger.error('Error while proxying request:', error);
347
+ if (!res.headersSent) {
348
+ res.statusCode = 500;
349
+ res.end('Internal Server Error');
350
+ }
351
+ resolve(true);
352
+ });
353
+
354
+ if (body) req.write(body);
355
+ req.end();
356
+ });
329
357
  } catch (error) {
330
358
  logger.error('Error while proxying request:', error);
331
- res.statusCode = 500;
332
- res.end('Internal Server Error');
359
+ if (!res.headersSent) {
360
+ res.statusCode = 500;
361
+ res.end('Internal Server Error');
362
+ }
333
363
  }
334
364
 
335
365
  return true;
@@ -3,6 +3,6 @@
3
3
  "dependencies": {
4
4
  "jsdom": "^25.0.1",
5
5
  "wirejs-dom": "^1.0.44",
6
- "wirejs-resources": "^0.1.168"
6
+ "wirejs-resources": "^0.1.169"
7
7
  }
8
8
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "wirejs-deploy-amplify-basic",
3
- "version": "0.1.168",
3
+ "version": "0.1.169",
4
4
  "type": "module",
5
5
  "main": "./dist/index.js",
6
6
  "types": "./dist/index.d.ts",
@@ -44,7 +44,7 @@
44
44
  "recursive-copy": "^2.0.14",
45
45
  "rimraf": "^6.0.1",
46
46
  "wirejs-dom": "^1.0.44",
47
- "wirejs-resources": "^0.1.168"
47
+ "wirejs-resources": "^0.1.169"
48
48
  },
49
49
  "devDependencies": {
50
50
  "@aws-amplify/backend": "^1.14.0",