@cloud-cli/px 3.1.3 → 3.1.4
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.
- package/dist/proxy.js +6 -3
- package/package.json +1 -1
package/dist/proxy.js
CHANGED
|
@@ -92,7 +92,7 @@ export class ProxyServer {
|
|
|
92
92
|
const url = new URL(req.url, target);
|
|
93
93
|
const isCorsPreflight = req.method === 'OPTIONS' && proxyEntry.cors;
|
|
94
94
|
if (isCorsPreflight) {
|
|
95
|
-
|
|
95
|
+
setCorsOriginHeader(req, res);
|
|
96
96
|
res.writeHead(204, 'OK');
|
|
97
97
|
res.end();
|
|
98
98
|
return;
|
|
@@ -107,8 +107,7 @@ export class ProxyServer {
|
|
|
107
107
|
setHeaders(proxyRes, res);
|
|
108
108
|
const isCorsSimple = req.method !== 'OPTIONS' && proxyEntry.cors && req.headers.origin;
|
|
109
109
|
if (isCorsSimple) {
|
|
110
|
-
|
|
111
|
-
res.setHeader('Access-Control-Allow-Origin', corsOrigin.origin);
|
|
110
|
+
setCorsOriginHeader(req, res);
|
|
112
111
|
}
|
|
113
112
|
res.writeHead(proxyRes.statusCode, proxyRes.statusMessage);
|
|
114
113
|
proxyRes.on('data', (chunk) => res.write(chunk));
|
|
@@ -167,3 +166,7 @@ function getHost(string) {
|
|
|
167
166
|
const url = new URL(string);
|
|
168
167
|
return url.hostname + (url.port ? ':' + url.port : '');
|
|
169
168
|
}
|
|
169
|
+
function setCorsOriginHeader(req, res) {
|
|
170
|
+
const corsOrigin = new URL(req.headers.origin);
|
|
171
|
+
res.setHeader('Access-Control-Allow-Origin', corsOrigin.host);
|
|
172
|
+
}
|