fixed vite with traefik https localhost
This commit is contained in:
@@ -10,11 +10,11 @@ global:
|
|||||||
|
|
||||||
vitehmr:
|
vitehmr:
|
||||||
js:
|
js:
|
||||||
http://localhost:5173/@vite/client:
|
https://localhost:5173/@vite/client:
|
||||||
type: external
|
type: external
|
||||||
attributes:
|
attributes:
|
||||||
type: module
|
type: module
|
||||||
http://localhost:5173/assets/js/main.js:
|
https://localhost:5173/assets/js/main.js:
|
||||||
type: external
|
type: external
|
||||||
attributes:
|
attributes:
|
||||||
type: module
|
type: module
|
||||||
|
|||||||
@@ -1,14 +1,52 @@
|
|||||||
import { defineConfig } from 'vite'
|
import { defineConfig } from 'vite'
|
||||||
import vue from '@vitejs/plugin-vue'
|
import vue from '@vitejs/plugin-vue'
|
||||||
import { fileURLToPath, URL } from 'node:url'
|
import { fileURLToPath, URL } from 'node:url'
|
||||||
|
import { readFileSync } from 'node:fs'
|
||||||
|
|
||||||
|
// Certificat mkcert wildcard du reverse-proxy (SAN: localhost, 127.0.0.1,
|
||||||
|
// *.localhost, trusté par la CA locale) : permet de servir le dev server
|
||||||
|
// en HTTPS sans toucher à la config Traefik.
|
||||||
|
const TLS_CERT = fileURLToPath(new URL('../../../../../../reverse-proxy/certs/wildcard.localhost.pem', import.meta.url))
|
||||||
|
const TLS_KEY = fileURLToPath(new URL('../../../../../../reverse-proxy/certs/wildcard.localhost-key.pem', import.meta.url))
|
||||||
|
|
||||||
// https://vitejs.dev/config/
|
// https://vitejs.dev/config/
|
||||||
export default defineConfig({
|
export default defineConfig({
|
||||||
plugins: [vue()],
|
plugins: [vue()],
|
||||||
|
// Chemins relatifs dans les assets buildés : sinon Vite génère des url()
|
||||||
|
// absolues depuis la racine du site au lieu du dossier du thème, où Drupal
|
||||||
|
// sert réellement assets/dist/.
|
||||||
|
base: './',
|
||||||
server: {
|
server: {
|
||||||
|
// The dev server must be reachable from the browser on the host.
|
||||||
|
host: 'localhost',
|
||||||
|
port: 5173,
|
||||||
|
strictPort: true,
|
||||||
|
// HTTPS obligatoire depuis la migration Traefik : la page Drupal est
|
||||||
|
// servie en https://mathallo.fr.localhost, un dev server en
|
||||||
|
// http://localhost:5173 serait bloqué en mixed content (assets + WebSocket
|
||||||
|
// HMR). On réutilise le certificat mkcert de reverse-proxy (SAN
|
||||||
|
// localhost/127.0.0.1) : aucun changement de config Traefik nécessaire.
|
||||||
|
https: {
|
||||||
|
cert: readFileSync(TLS_CERT),
|
||||||
|
key: readFileSync(TLS_KEY),
|
||||||
|
},
|
||||||
|
// Vite 5.4 crée un serveur HTTP/2 (createSecureServer) dès que `https`
|
||||||
|
// est défini, sauf si `proxy` est présent — et HTTP/2 ne supporte pas
|
||||||
|
// l'upgrade WebSocket : le HMR (wss://localhost:5173) serait refusé
|
||||||
|
// (404 / close 1006). Un `proxy: {}` vide force le serveur HTTPS en
|
||||||
|
// HTTP/1.1 (node:https) sans changer le comportement des requêtes.
|
||||||
|
proxy: {},
|
||||||
|
// Depuis Vite 5.4.12 (CVE-2025-24010) CORS est désactivé par défaut.
|
||||||
|
// Autorise explicitement les origines qui servent les pages Drupal.
|
||||||
|
cors: {
|
||||||
|
origin: [/^https:\/\/mathallo\.fr\.localhost(:\d+)?$/, /^https:\/\/dev\.mathallo\.fr(:\d+)?$/],
|
||||||
|
},
|
||||||
|
// Absolute base URL used by Vite to build asset/HMR URLs.
|
||||||
|
origin: 'https://localhost:5173',
|
||||||
hmr: {
|
hmr: {
|
||||||
host: 'localhost',
|
host: 'localhost',
|
||||||
|
protocol: 'wss',
|
||||||
|
clientPort: 5173,
|
||||||
},
|
},
|
||||||
watch: {
|
watch: {
|
||||||
usePolling: true,
|
usePolling: true,
|
||||||
|
|||||||
Reference in New Issue
Block a user