vite-plugin-php 3.0.0-beta.2 → 3.0.0-beta.3
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 +15 -0
- package/dist/index.cjs +10 -6
- package/dist/index.mjs +10 -6
- package/package.json +1 -1
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
|
@@ -10884,19 +10884,23 @@ const phpProxy = async (req, res, next) => {
|
|
|
10884
10884
|
req.on("error", (error) => {
|
|
10885
10885
|
throw error;
|
|
10886
10886
|
});
|
|
10887
|
-
|
|
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
|
|
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
|
-
|
|
10898
|
-
|
|
10899
|
-
|
|
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
|
@@ -10867,19 +10867,23 @@ const phpProxy = async (req, res, next) => {
|
|
|
10867
10867
|
req.on("error", (error) => {
|
|
10868
10868
|
throw error;
|
|
10869
10869
|
});
|
|
10870
|
-
|
|
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
|
|
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
|
-
|
|
10881
|
-
|
|
10882
|
-
|
|
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()
|