From 6a9a4a4d964432da2c39561dbd551430c77ffc6d Mon Sep 17 00:00:00 2001 From: riccio82 Date: Fri, 24 Apr 2026 12:00:46 +0200 Subject: [PATCH] Add Vite dev server proxy config and vite-proxy toggle script Add Apache reverse proxy configuration for Vite dev server (HMR, module resolution, source file serving) and a CLI helper script to toggle the proxy on/off inside the container. - vite-dev-proxy.inc: proxies @vite, @fs, HMR websocket, public/, plugins/, node_modules/ to localhost:5173; sets VITE_DEV env var for PHP dev-mode asset injection; disables caching on proxied paths - 443-matecat.conf: adds commented-out IncludeOptional for the proxy - vite-proxy.sh: on/off/status CLI tool installed to /usr/local/bin - Dockerfile: copies and chmods the vite-proxy script Usage: vite-proxy on && yarn watch --- MateCat-Noble/MateCatApache/Dockerfile | 2 + .../apache2/sites-enabled/443-matecat.conf | 1 + .../data/etc/apache2/vite-dev-proxy.inc | 44 +++++++++++++++++++ MateCat-Noble/MateCatApache/vite-proxy.sh | 29 ++++++++++++ 4 files changed, 76 insertions(+) create mode 100644 MateCat-Noble/MateCatApache/data/etc/apache2/vite-dev-proxy.inc create mode 100644 MateCat-Noble/MateCatApache/vite-proxy.sh diff --git a/MateCat-Noble/MateCatApache/Dockerfile b/MateCat-Noble/MateCatApache/Dockerfile index 0dc4c2f..c65ec7d 100644 --- a/MateCat-Noble/MateCatApache/Dockerfile +++ b/MateCat-Noble/MateCatApache/Dockerfile @@ -70,8 +70,10 @@ RUN #phpenmod mcrypt COPY run_plugin_js_build.sh /tmp/run_plugin_js_build.sh COPY run.sh /tmp/run.sh +COPY vite-proxy.sh /usr/local/bin/vite-proxy RUN chmod +x /tmp/run_plugin_js_build.sh RUN chmod +x /tmp/run.sh +RUN chmod +x /usr/local/bin/vite-proxy WORKDIR "/var/www/matecat" CMD ["/tmp/run.sh"] diff --git a/MateCat-Noble/MateCatApache/data/etc/apache2/sites-enabled/443-matecat.conf b/MateCat-Noble/MateCatApache/data/etc/apache2/sites-enabled/443-matecat.conf index 7e924cb..2d28ead 100644 --- a/MateCat-Noble/MateCatApache/data/etc/apache2/sites-enabled/443-matecat.conf +++ b/MateCat-Noble/MateCatApache/data/etc/apache2/sites-enabled/443-matecat.conf @@ -12,6 +12,7 @@ + #IncludeOptional /etc/apache2/vite-dev-proxy.inc ServerAdmin webmaster@localhost ServerName dev.matecat.com diff --git a/MateCat-Noble/MateCatApache/data/etc/apache2/vite-dev-proxy.inc b/MateCat-Noble/MateCatApache/data/etc/apache2/vite-dev-proxy.inc new file mode 100644 index 0000000..e34a3b2 --- /dev/null +++ b/MateCat-Noble/MateCatApache/data/etc/apache2/vite-dev-proxy.inc @@ -0,0 +1,44 @@ +# Vite dev server reverse proxy (included from VirtualHost) +# Toggle with: vite-proxy on|off|status + +# Disable caching for proxied paths + + ExpiresActive Off + Header always unset Expires + Header always set Cache-Control "no-store" + + + ExpiresActive Off + Header always unset Expires + Header always set Cache-Control "no-store" + + +# HMR WebSocket +RewriteCond %{HTTP:Upgrade} websocket [NC] +RewriteCond %{HTTP:Connection} upgrade [NC] +RewriteRule ^/__vite_hmr(.*)$ "ws://127.0.0.1:5173/__vite_hmr$1" [P,L] + +# Proxy Vite paths (before .htaccess static file serving) +ProxyPass "/__vite_hmr" "ws://127.0.0.1:5173/__vite_hmr" +ProxyPassReverse "/__vite_hmr" "ws://127.0.0.1:5173/__vite_hmr" +ProxyPass "/@vite" "http://127.0.0.1:5173/@vite" +ProxyPassReverse "/@vite" "http://127.0.0.1:5173/@vite" +ProxyPass "/@react-refresh" "http://127.0.0.1:5173/@react-refresh" +ProxyPassReverse "/@react-refresh" "http://127.0.0.1:5173/@react-refresh" +ProxyPass "/@fs/" "http://127.0.0.1:5173/@fs/" +ProxyPassReverse "/@fs/" "http://127.0.0.1:5173/@fs/" +ProxyPass "/vite-entries/" "http://127.0.0.1:5173/vite-entries/" +ProxyPassReverse "/vite-entries/" "http://127.0.0.1:5173/vite-entries/" +ProxyPass "/public/" "http://127.0.0.1:5173/public/" +ProxyPassReverse "/public/" "http://127.0.0.1:5173/public/" +ProxyPass "/plugins/" "http://127.0.0.1:5173/plugins/" +ProxyPassReverse "/plugins/" "http://127.0.0.1:5173/plugins/" +ProxyPass "/node_modules/" "http://127.0.0.1:5173/node_modules/" +ProxyPassReverse "/node_modules/" "http://127.0.0.1:5173/node_modules/" + +SetEnv VITE_DEV 1 + +# Longer timeout for Vite (SCSS compilation can be slow on first load) + + ProxySet timeout=120 + diff --git a/MateCat-Noble/MateCatApache/vite-proxy.sh b/MateCat-Noble/MateCatApache/vite-proxy.sh new file mode 100644 index 0000000..29cf86b --- /dev/null +++ b/MateCat-Noble/MateCatApache/vite-proxy.sh @@ -0,0 +1,29 @@ +#!/bin/bash +# Toggle Vite dev server reverse proxy in Apache +# Usage: vite-proxy {on|off|status} + +CONF="/etc/apache2/sites-enabled/443-matecat.conf" +ENABLED="IncludeOptional /etc/apache2/vite-dev-proxy.inc" +DISABLED="#IncludeOptional /etc/apache2/vite-dev-proxy.inc" + +case "$1" in + on) + sed -i "s|${DISABLED}|${ENABLED}|" "$CONF" && apachectl graceful + echo "Vite dev proxy enabled. Run 'yarn watch' to start Vite." + ;; + off) + sed -i "s|${ENABLED}|${DISABLED}|" "$CONF" && apachectl graceful + echo "Vite dev proxy disabled. Apache serves static builds." + ;; + status) + if grep -q "^[[:space:]]*IncludeOptional.*/vite-dev-proxy.inc" "$CONF"; then + echo "ON" + else + echo "OFF" + fi + ;; + *) + echo "Usage: vite-proxy {on|off|status}" + exit 1 + ;; +esac