Browse Source

Bypass /photo in the BrowserSync proxy

Browsing daw.stu:81/photo looped to daw.stu:81//daw.stu:81/photo/photo/.
The proxy rewrites absolute URLs to protocol-relative so navigation stays on
:81, turning Lychee's <base href="https://daw.stu/photo"> into
"//daw.stu:81/photo". vue-router derives its base from <base href> and strips
the origin with /^\w+:\/\/[^\/]+/ -- that needs a scheme, so the
protocol-relative form slips through and becomes the router base, doubling
every route.

Nothing in the watch list covers /photo (separate app, own Vite build), so
302 it to the real vhost instead. WP pages still proxy with the bs snippet.

Verified on a scratch port: /photo, /photo/ and /photo/gallery all 302 to
daw.stu; / still 200s with browser-sync-client injected.
David A. Windham 1 week ago
parent
commit
871b33e57f
1 changed files with 17 additions and 0 deletions
  1. 17 0
      webpack.config.js

+ 17 - 0
webpack.config.js

@@ -94,6 +94,23 @@ module.exports = {
         key: '/opt/homebrew/etc/httpd/ssl/daw.stu-key.pem',
         cert: '/opt/homebrew/etc/httpd/ssl/daw.stu-cert.pem',
       },
+      // Bounce /photo (Lychee) off the proxy and onto the real vhost. The proxy
+      // rewrites absolute URLs to protocol-relative so navigation stays on :81,
+      // which turns Lychee's <base href="https://daw.stu/photo"> into
+      // "//daw.stu:81/photo". vue-router strips the origin off <base href> with
+      // /^\w+:\/\/[^\/]+/ -- that needs a scheme, so protocol-relative slips
+      // through and becomes the router base, doubling every route into
+      // /photo/photo/. Nothing below watches /photo (it's a separate app with its
+      // own Vite build), so there's nothing to gain by proxying it.
+      middleware: [
+        function bypassLychee(req, res, next) {
+          if (req.url === '/photo' || req.url.startsWith('/photo/')) {
+            res.writeHead(302, { Location: 'https://daw.stu' + req.url });
+            return res.end();
+          }
+          return next();
+        },
+      ],
       files: [
         './**/*.php',
         './src/**/*.js',