wirejs-deploy-amplify-basic 0.1.168 → 0.1.170
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
|
|
|
@@ -304,32 +305,62 @@ async function tryEndpointPath(context, res) {
|
|
|
304
305
|
*/
|
|
305
306
|
async function proxyRequest(context, res, targetUrl) {
|
|
306
307
|
const method = context.httpMethod;
|
|
308
|
+
const parsedUrl = new URL(targetUrl);
|
|
307
309
|
const headers = {
|
|
308
310
|
...context.requestHeaders,
|
|
311
|
+
'host': parsedUrl.hostname,
|
|
309
312
|
'x-wirejs-location': context.location.toString()
|
|
310
313
|
};
|
|
311
314
|
const body = context.requestBody;
|
|
312
315
|
|
|
313
316
|
try {
|
|
314
|
-
const
|
|
315
|
-
const
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
317
|
+
const isHttps = parsedUrl.protocol === 'https:';
|
|
318
|
+
const requester = isHttps ? https : http;
|
|
319
|
+
|
|
320
|
+
return await new Promise((resolve) => {
|
|
321
|
+
const req = requester.request({
|
|
322
|
+
hostname: parsedUrl.hostname,
|
|
323
|
+
port: parsedUrl.port || (isHttps ? 443 : 80),
|
|
324
|
+
path: parsedUrl.pathname + (parsedUrl.search || ''),
|
|
325
|
+
method,
|
|
326
|
+
headers,
|
|
327
|
+
}, (proxyRes) => {
|
|
328
|
+
res.statusCode = proxyRes.statusCode;
|
|
329
|
+
|
|
330
|
+
for (const [header, value] of Object.entries(proxyRes.headers)) {
|
|
331
|
+
if (header === 'x-wirejs-redirect') {
|
|
332
|
+
res.setHeader('Location', value);
|
|
333
|
+
} else {
|
|
334
|
+
res.setHeader(header, value);
|
|
335
|
+
}
|
|
336
|
+
}
|
|
327
337
|
|
|
328
|
-
|
|
338
|
+
const chunks = [];
|
|
339
|
+
proxyRes.on('data', chunk => chunks.push(chunk));
|
|
340
|
+
proxyRes.on('end', () => {
|
|
341
|
+
res.end(Buffer.concat(chunks));
|
|
342
|
+
resolve(true);
|
|
343
|
+
});
|
|
344
|
+
});
|
|
345
|
+
|
|
346
|
+
req.on('error', (error) => {
|
|
347
|
+
logger.error('Error while proxying request:', error);
|
|
348
|
+
if (!res.headersSent) {
|
|
349
|
+
res.statusCode = 500;
|
|
350
|
+
res.end('Internal Server Error');
|
|
351
|
+
}
|
|
352
|
+
resolve(true);
|
|
353
|
+
});
|
|
354
|
+
|
|
355
|
+
if (body) req.write(body);
|
|
356
|
+
req.end();
|
|
357
|
+
});
|
|
329
358
|
} catch (error) {
|
|
330
359
|
logger.error('Error while proxying request:', error);
|
|
331
|
-
res.
|
|
332
|
-
|
|
360
|
+
if (!res.headersSent) {
|
|
361
|
+
res.statusCode = 500;
|
|
362
|
+
res.end('Internal Server Error');
|
|
363
|
+
}
|
|
333
364
|
}
|
|
334
365
|
|
|
335
366
|
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.170",
|
|
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.170"
|
|
48
48
|
},
|
|
49
49
|
"devDependencies": {
|
|
50
50
|
"@aws-amplify/backend": "^1.14.0",
|