@cloud-cli/px 3.3.0 → 3.3.1

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.
Files changed (2) hide show
  1. package/dist/proxy.js +8 -7
  2. package/package.json +1 -1
package/dist/proxy.js CHANGED
@@ -105,8 +105,8 @@ export class ProxyServer {
105
105
  const url = new URL(req.url, target);
106
106
  const isCorsPreflight = req.method === 'OPTIONS' && proxyEntry.cors;
107
107
  if (isCorsPreflight) {
108
- setCorsOriginHeader(req, res);
109
- res.writeHead(204, 'OK');
108
+ setCorsHeaders(req, res);
109
+ res.writeHead(204, { 'Content-Length': '0' });
110
110
  res.end();
111
111
  return;
112
112
  }
@@ -120,7 +120,7 @@ export class ProxyServer {
120
120
  setHeaders(proxyRes, res);
121
121
  const isCorsSimple = req.method !== 'OPTIONS' && proxyEntry.cors && req.headers.origin;
122
122
  if (isCorsSimple) {
123
- setCorsOriginHeader(req, res);
123
+ setCorsHeaders(req, res);
124
124
  }
125
125
  res.writeHead(proxyRes.statusCode, proxyRes.statusMessage);
126
126
  proxyRes.on('data', (chunk) => res.write(chunk));
@@ -179,10 +179,11 @@ function getHost(string) {
179
179
  const url = new URL(string);
180
180
  return url.hostname + (url.port ? ':' + url.port : '');
181
181
  }
182
- function setCorsOriginHeader(req, res) {
183
- const corsOrigin = new URL(req.headers.origin);
184
- res.setHeader('Access-Control-Allow-Origin', corsOrigin.origin);
182
+ function setCorsHeaders(req, res) {
183
+ const corsOrigin = new URL(req.headers.origin).origin;
184
+ res.setHeader('Vary', 'Origin');
185
+ res.setHeader('Access-Control-Allow-Origin', corsOrigin);
185
186
  res.setHeader('Access-Control-Allow-Headers', '*');
186
- res.setHeader('Access-Control-Allow-Methods', '*');
187
+ res.setHeader('Access-Control-Allow-Methods', 'GET,HEAD,PUT,PATCH,POST,DELETE');
187
188
  res.setHeader('Access-Control-Allow-Credentials', 'true');
188
189
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@cloud-cli/px",
3
- "version": "3.3.0",
3
+ "version": "3.3.1",
4
4
  "description": "Reverse Proxy",
5
5
  "main": "dist/index.js",
6
6
  "type": "module",