wirejs-deploy-amplify-basic 0.0.19-alpha → 0.0.21-alpha
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.
|
@@ -194,11 +194,10 @@ async function postData(request) {
|
|
|
194
194
|
});
|
|
195
195
|
};
|
|
196
196
|
|
|
197
|
-
async function
|
|
197
|
+
async function tryAPIPath(req, res) {
|
|
198
198
|
if (!API_URL) {
|
|
199
199
|
logger.error('Tried to proxy without API_URL config.');
|
|
200
|
-
|
|
201
|
-
res.end('500 - Internal Server Error');
|
|
200
|
+
return false;
|
|
202
201
|
}
|
|
203
202
|
return proxyRequest(req, res, API_URL);
|
|
204
203
|
}
|
|
@@ -213,11 +212,11 @@ async function proxyRequest(req, res, targetUrl) {
|
|
|
213
212
|
try {
|
|
214
213
|
const response = await fetch(targetUrl, fetchOptions);
|
|
215
214
|
const responseBody = await response.text();
|
|
216
|
-
const responseHeaders = response.headers
|
|
215
|
+
const responseHeaders = response.headers;
|
|
217
216
|
|
|
218
217
|
res.statusCode = response.status;
|
|
219
|
-
|
|
220
|
-
res.setHeader(header, responseHeaders
|
|
218
|
+
responseHeaders.keys().forEach((header) => {
|
|
219
|
+
res.setHeader(header, responseHeaders.get(header));
|
|
221
220
|
});
|
|
222
221
|
|
|
223
222
|
res.end(responseBody);
|
|
@@ -226,6 +225,8 @@ async function proxyRequest(req, res, targetUrl) {
|
|
|
226
225
|
res.statusCode = 500;
|
|
227
226
|
res.end('Internal Server Error');
|
|
228
227
|
}
|
|
228
|
+
|
|
229
|
+
return true;
|
|
229
230
|
}
|
|
230
231
|
|
|
231
232
|
/**
|
|
@@ -239,6 +240,7 @@ async function handleRequest(req, res) {
|
|
|
239
240
|
|
|
240
241
|
if (await trySSRScriptPath(req, res)) return;
|
|
241
242
|
if (await trySSRPath(req, res)) return;
|
|
243
|
+
if (await tryAPIPath(req, res)) return;
|
|
242
244
|
|
|
243
245
|
// if we've made it this far, we don't have what you're looking for
|
|
244
246
|
res.statusCode = '404';
|