vite-plugin-php 2.0.3 → 2.0.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/README.md CHANGED
@@ -179,6 +179,21 @@ usePHP({
179
179
  });
180
180
  ```
181
181
 
182
+ Since version 2.0.4 it is possible to point to some external files. Make sure the change URL points to an external origin:
183
+
184
+ ```js
185
+ usePHP({
186
+ rewriteUrl(requestUrl) {
187
+ if (requestUrl.pathname.startsWith('/media/')) {
188
+ return new URL(
189
+ 'https://nititech.de' +
190
+ requestUrl.toString().substring(requestUrl.origin.length),
191
+ );
192
+ }
193
+ },
194
+ });
195
+ ```
196
+
182
197
  ⚠️ **Attention:** If using the rewriteUrl property you will need to exclude (_return undefined_) assets like CSS, JavaScript, Images, etc.., that match your transpiled php file names, on your own!
183
198
 
184
199
  #### Error logging
package/dist/index.cjs CHANGED
@@ -7833,19 +7833,23 @@ const servePlugin = {
7833
7833
  req.on("error", (error) => {
7834
7834
  throw error;
7835
7835
  });
7836
- const url = new URL(req.url, "http://localhost");
7836
+ let url = new URL(req.url, "http://localhost");
7837
7837
  if (shared.viteConfig?.server.port) {
7838
7838
  url.port = shared.viteConfig.server.port.toString();
7839
7839
  }
7840
- const requestUrl = url.pathname;
7840
+ const requestUrl = new URL(url);
7841
7841
  if (url.pathname.endsWith("/")) {
7842
7842
  url.pathname += "index.php";
7843
7843
  }
7844
7844
  const routedUrl = serve.rewriteUrl(url);
7845
7845
  if (routedUrl) {
7846
- url.pathname = routedUrl.pathname;
7847
- url.search = routedUrl.search;
7848
- url.hash = routedUrl.hash;
7846
+ if (routedUrl.origin !== requestUrl.origin) {
7847
+ res.writeHead(307, {
7848
+ location: routedUrl.toString()
7849
+ }).end();
7850
+ return;
7851
+ }
7852
+ url = routedUrl;
7849
7853
  }
7850
7854
  const entryPathname = url.pathname.substring(1);
7851
7855
  const entry = shared.entries.find((file) => {
@@ -7860,7 +7864,7 @@ const servePlugin = {
7860
7864
  url.searchParams.set(
7861
7865
  internalParam,
7862
7866
  new URLSearchParams({
7863
- $REQUEST_URI: requestUrl,
7867
+ $REQUEST_URI: requestUrl.pathname,
7864
7868
  $PHP_SELF: "/" + entry,
7865
7869
  temp_dir: shared.tempDir,
7866
7870
  error_levels: shared.devConfig.errorLevels.toString()
@@ -7920,9 +7924,9 @@ const servePlugin = {
7920
7924
  "html"
7921
7925
  )) {
7922
7926
  out = await server.transformIndexHtml(
7923
- `/${entry}.html:${requestUrl}`,
7927
+ `/${entry}.html:${requestUrl.pathname}`,
7924
7928
  out,
7925
- requestUrl
7929
+ requestUrl.pathname
7926
7930
  );
7927
7931
  }
7928
7932
  res.writeHead(
package/dist/index.mjs CHANGED
@@ -7817,19 +7817,23 @@ const servePlugin = {
7817
7817
  req.on("error", (error) => {
7818
7818
  throw error;
7819
7819
  });
7820
- const url = new URL(req.url, "http://localhost");
7820
+ let url = new URL(req.url, "http://localhost");
7821
7821
  if (shared.viteConfig?.server.port) {
7822
7822
  url.port = shared.viteConfig.server.port.toString();
7823
7823
  }
7824
- const requestUrl = url.pathname;
7824
+ const requestUrl = new URL(url);
7825
7825
  if (url.pathname.endsWith("/")) {
7826
7826
  url.pathname += "index.php";
7827
7827
  }
7828
7828
  const routedUrl = serve.rewriteUrl(url);
7829
7829
  if (routedUrl) {
7830
- url.pathname = routedUrl.pathname;
7831
- url.search = routedUrl.search;
7832
- url.hash = routedUrl.hash;
7830
+ if (routedUrl.origin !== requestUrl.origin) {
7831
+ res.writeHead(307, {
7832
+ location: routedUrl.toString()
7833
+ }).end();
7834
+ return;
7835
+ }
7836
+ url = routedUrl;
7833
7837
  }
7834
7838
  const entryPathname = url.pathname.substring(1);
7835
7839
  const entry = shared.entries.find((file) => {
@@ -7844,7 +7848,7 @@ const servePlugin = {
7844
7848
  url.searchParams.set(
7845
7849
  internalParam,
7846
7850
  new URLSearchParams({
7847
- $REQUEST_URI: requestUrl,
7851
+ $REQUEST_URI: requestUrl.pathname,
7848
7852
  $PHP_SELF: "/" + entry,
7849
7853
  temp_dir: shared.tempDir,
7850
7854
  error_levels: shared.devConfig.errorLevels.toString()
@@ -7904,9 +7908,9 @@ const servePlugin = {
7904
7908
  "html"
7905
7909
  )) {
7906
7910
  out = await server.transformIndexHtml(
7907
- `/${entry}.html:${requestUrl}`,
7911
+ `/${entry}.html:${requestUrl.pathname}`,
7908
7912
  out,
7909
- requestUrl
7913
+ requestUrl.pathname
7910
7914
  );
7911
7915
  }
7912
7916
  res.writeHead(
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "vite-plugin-php",
3
- "version": "2.0.3",
3
+ "version": "2.0.4",
4
4
  "author": "Nikita 'donnikitos' Nitichevski <me@donnikitos.com> (https://donnikitos.com/)",
5
5
  "repository": {
6
6
  "type": "git",