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
|
|
315
|
-
const
|
|
316
|
-
const
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
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
|
-
|
|
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.
|
|
332
|
-
|
|
359
|
+
if (!res.headersSent) {
|
|
360
|
+
res.statusCode = 500;
|
|
361
|
+
res.end('Internal Server Error');
|
|
362
|
+
}
|
|
333
363
|
}
|
|
334
364
|
|
|
335
365
|
return true;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "wirejs-deploy-amplify-basic",
|
|
3
|
-
"version": "0.1.
|
|
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.
|
|
47
|
+
"wirejs-resources": "^0.1.169"
|
|
48
48
|
},
|
|
49
49
|
"devDependencies": {
|
|
50
50
|
"@aws-amplify/backend": "^1.14.0",
|