From 98db8263ef010183304de6ddab3b33e8d02492da Mon Sep 17 00:00:00 2001 From: Mathieu De Keyzer Date: Fri, 11 Oct 2024 08:44:19 +0200 Subject: [PATCH] feat: proxy to backend (JS/TS related css are loaded via the script => so empty css in that case) --- EMS/admin-ui-bundle/assets/css/empty.css | 0 EMS/admin-ui-bundle/assets/vite.config.ts | 16 ++++++++++++++++ .../src/Helper/Asset/AssetVersionStrategy.php | 9 ++++++++- 3 files changed, 24 insertions(+), 1 deletion(-) create mode 100644 EMS/admin-ui-bundle/assets/css/empty.css diff --git a/EMS/admin-ui-bundle/assets/css/empty.css b/EMS/admin-ui-bundle/assets/css/empty.css new file mode 100644 index 000000000..e69de29bb diff --git a/EMS/admin-ui-bundle/assets/vite.config.ts b/EMS/admin-ui-bundle/assets/vite.config.ts index 15500921c..47cdfae17 100644 --- a/EMS/admin-ui-bundle/assets/vite.config.ts +++ b/EMS/admin-ui-bundle/assets/vite.config.ts @@ -3,6 +3,22 @@ import { resolve } from 'path' import inject from '@rollup/plugin-inject' export default defineConfig({ + server: { + proxy: { + '/index.php': { + target: 'http://127.0.0.1:8881', + changeOrigin: false, + secure: false, + xfwd: true, + }, + '/bundles': { + target: 'http://127.0.0.1:8881', + changeOrigin: false, + secure: false, + xfwd: true, + }, + }, + }, plugins: [ inject({ jQuery: 'jquery', diff --git a/EMS/admin-ui-bundle/src/Helper/Asset/AssetVersionStrategy.php b/EMS/admin-ui-bundle/src/Helper/Asset/AssetVersionStrategy.php index b0c33ad98..db866a7dc 100644 --- a/EMS/admin-ui-bundle/src/Helper/Asset/AssetVersionStrategy.php +++ b/EMS/admin-ui-bundle/src/Helper/Asset/AssetVersionStrategy.php @@ -34,7 +34,14 @@ public function applyVersion(string $path): string private function getManifestPath(string $path): string { if (!isset($this->manifestData)) { - $manifestPath = $this->fileLocator->locate('@EMSAdminUIBundle/Resources/public/.vite/manifest.json'); + try { + $manifestPath = $this->fileLocator->locate('@EMSAdminUIBundle/Resources/public/.vite/manifest.json'); + } catch (\Throwable) { + if (\preg_match('/(?.*\.(js|ts|cjs))(\.(?[0-9]+))?\.css$/', $path)) { + return 'css/empty.css'; + } + return $path; + } if (!\is_file($manifestPath)) { throw new RuntimeException(\sprintf('Asset manifest file "%s" does not exist. Did you forget to build the assets with npm or yarn?', $manifestPath)); }