vite-plugin-php 3.0.0-beta.2 → 3.0.0-beta.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
@@ -171,6 +171,21 @@ usePHP({
171
171
  });
172
172
  ```
173
173
 
174
+ Since version 2.0.4 it is possible to point to some external files. Make sure the change URL points to an external origin:
175
+
176
+ ```js
177
+ usePHP({
178
+ rewriteUrl(requestUrl) {
179
+ if (requestUrl.pathname.startsWith('/media/')) {
180
+ return new URL(
181
+ 'https://nititech.de' +
182
+ requestUrl.toString().substring(requestUrl.origin.length),
183
+ );
184
+ }
185
+ },
186
+ });
187
+ ```
188
+
174
189
  ⚠️ **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!
175
190
 
176
191
  #### Error logging
package/dist/index.cjs CHANGED
@@ -10841,7 +10841,7 @@ const assetsPattern = new RegExp(
10841
10841
  );
10842
10842
  const viteClientInjection = '<script type="module" src="/@vite/client"><\/script>\n';
10843
10843
  const viteClientInjectionPattern = new RegExp(
10844
- '<script.+?src="/@vite/client".+?<\/script>(\r\n|\n|\r)',
10844
+ '<script[^>]+?src="/@vite/client".+?<\/script>(\r\n|\n|\r)',
10845
10845
  "si"
10846
10846
  );
10847
10847
  const lastTagPattern = new RegExp(`^(.+(?:</.+?>|<.+?/>))(.+|)$`, "si");
@@ -10884,19 +10884,23 @@ const phpProxy = async (req, res, next) => {
10884
10884
  req.on("error", (error) => {
10885
10885
  throw error;
10886
10886
  });
10887
- const url = new URL(req.url, "http://localhost");
10887
+ let url = new URL(req.url, "http://localhost");
10888
10888
  if (shared.viteConfig?.server.port) {
10889
10889
  url.port = shared.viteConfig.server.port.toString();
10890
10890
  }
10891
- const requestUrl = url.pathname;
10891
+ const requestUrl = new URL(url);
10892
10892
  if (url.pathname.endsWith("/")) {
10893
10893
  url.pathname += "index.php";
10894
10894
  }
10895
10895
  const routedUrl = serve.rewriteUrl(url);
10896
10896
  if (routedUrl) {
10897
- url.pathname = routedUrl.pathname;
10898
- url.search = routedUrl.search;
10899
- url.hash = routedUrl.hash;
10897
+ if (routedUrl.origin !== requestUrl.origin) {
10898
+ res.writeHead(307, {
10899
+ location: routedUrl.toString()
10900
+ }).end();
10901
+ return;
10902
+ }
10903
+ url = routedUrl;
10900
10904
  }
10901
10905
  const entryPathname = url.pathname.substring(1);
10902
10906
  const entry = shared.entries.find((file) => {
@@ -10911,7 +10915,7 @@ const phpProxy = async (req, res, next) => {
10911
10915
  url.searchParams.set(
10912
10916
  internalParam,
10913
10917
  new URLSearchParams({
10914
- $REQUEST_URI: requestUrl,
10918
+ $REQUEST_URI: requestUrl.pathname,
10915
10919
  $PHP_SELF: "/" + entry,
10916
10920
  temp_dir: shared.tempDir,
10917
10921
  error_levels: shared.devConfig.errorLevels.toString()
package/dist/index.mjs CHANGED
@@ -10824,7 +10824,7 @@ const assetsPattern = new RegExp(
10824
10824
  );
10825
10825
  const viteClientInjection = '<script type="module" src="/@vite/client"><\/script>\n';
10826
10826
  const viteClientInjectionPattern = new RegExp(
10827
- '<script.+?src="/@vite/client".+?<\/script>(\r\n|\n|\r)',
10827
+ '<script[^>]+?src="/@vite/client".+?<\/script>(\r\n|\n|\r)',
10828
10828
  "si"
10829
10829
  );
10830
10830
  const lastTagPattern = new RegExp(`^(.+(?:</.+?>|<.+?/>))(.+|)$`, "si");
@@ -10867,19 +10867,23 @@ const phpProxy = async (req, res, next) => {
10867
10867
  req.on("error", (error) => {
10868
10868
  throw error;
10869
10869
  });
10870
- const url = new URL(req.url, "http://localhost");
10870
+ let url = new URL(req.url, "http://localhost");
10871
10871
  if (shared.viteConfig?.server.port) {
10872
10872
  url.port = shared.viteConfig.server.port.toString();
10873
10873
  }
10874
- const requestUrl = url.pathname;
10874
+ const requestUrl = new URL(url);
10875
10875
  if (url.pathname.endsWith("/")) {
10876
10876
  url.pathname += "index.php";
10877
10877
  }
10878
10878
  const routedUrl = serve.rewriteUrl(url);
10879
10879
  if (routedUrl) {
10880
- url.pathname = routedUrl.pathname;
10881
- url.search = routedUrl.search;
10882
- url.hash = routedUrl.hash;
10880
+ if (routedUrl.origin !== requestUrl.origin) {
10881
+ res.writeHead(307, {
10882
+ location: routedUrl.toString()
10883
+ }).end();
10884
+ return;
10885
+ }
10886
+ url = routedUrl;
10883
10887
  }
10884
10888
  const entryPathname = url.pathname.substring(1);
10885
10889
  const entry = shared.entries.find((file) => {
@@ -10894,7 +10898,7 @@ const phpProxy = async (req, res, next) => {
10894
10898
  url.searchParams.set(
10895
10899
  internalParam,
10896
10900
  new URLSearchParams({
10897
- $REQUEST_URI: requestUrl,
10901
+ $REQUEST_URI: requestUrl.pathname,
10898
10902
  $PHP_SELF: "/" + entry,
10899
10903
  temp_dir: shared.tempDir,
10900
10904
  error_levels: shared.devConfig.errorLevels.toString()
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "vite-plugin-php",
3
- "version": "3.0.0-beta.2",
3
+ "version": "3.0.0-beta.4",
4
4
  "author": "Nikita 'donnikitos' Nitichevski <me@donnikitos.com> (https://donnikitos.com/)",
5
5
  "repository": {
6
6
  "type": "git",
@@ -16,7 +16,7 @@
16
16
  "tcp-port-used": "^1.0.2",
17
17
  "typescript": "^5.8.3",
18
18
  "unbuild": "^3.5.0",
19
- "vite": "^5.4.10"
19
+ "vite": "^5.4.21"
20
20
  },
21
21
  "exports": {
22
22
  ".": {