get ingress to play nice with vite

This commit is contained in:
Blake Blackshear 2022-05-19 07:31:02 -05:00
parent 7b2b5bfa71
commit ca7bad8909
6 changed files with 12 additions and 10 deletions

View File

@ -205,11 +205,13 @@ http {
add_header Cache-Control "public";
}
sub_filter 'href="/' 'href="$http_x_ingress_path/';
sub_filter 'url(/' 'url($http_x_ingress_path/';
sub_filter '"/dist/' '"$http_x_ingress_path/dist/';
sub_filter '"/js/' '"$http_x_ingress_path/js/';
sub_filter '<body>' '<body><script>window.baseUrl="$http_x_ingress_path";</script>';
sub_filter 'href="/BASE_PATH/' 'href="$http_x_ingress_path/';
sub_filter 'url(/BASE_PATH/' 'url($http_x_ingress_path/';
sub_filter '"/BASE_PATH/dist/' '"$http_x_ingress_path/dist/';
sub_filter '"/BASE_PATH/js/' '"$http_x_ingress_path/js/';
sub_filter '"/BASE_PATH/assets/' '"$http_x_ingress_path/assets/';
sub_filter '="/BASE_PATH/"' '=window.baseUrl';
sub_filter '<body>' '<body><script>window.baseUrl="$http_x_ingress_path/";</script>';
sub_filter_types text/css application/javascript;
sub_filter_once off;

View File

@ -5,7 +5,7 @@
"scripts": {
"dev": "vite",
"lint": "eslint ./ --ext .jsx,.js,.tsx,.ts",
"build": "tsc && vite build",
"build": "tsc && vite build --base=/BASE_PATH/",
"preview": "vite preview",
"test": "jest"
},

View File

@ -1,2 +1,2 @@
import { API_HOST } from '../env';
export const baseUrl = API_HOST || `${window.location.protocol}//${window.location.host}${window.baseUrl || ''}`;
export const baseUrl = API_HOST || `${window.location.protocol}//${window.location.host}${window.baseUrl || '/'}`;

View File

@ -4,7 +4,7 @@ import useSWR, { SWRConfig } from 'swr';
import { MqttProvider } from './mqtt';
import axios from 'axios';
axios.defaults.baseURL = `${baseUrl}/api/`;
axios.defaults.baseURL = `${baseUrl}api/`;
export function ApiProvider({ children, options }) {
return (

View File

@ -34,7 +34,7 @@ export function MqttProvider({
config,
children,
createWebsocket = defaultCreateWebsocket,
mqttUrl = `${baseUrl.replace(/^http/, 'ws')}/ws`,
mqttUrl = `${baseUrl.replace(/^http/, 'ws')}ws`,
}) {
const [state, dispatch] = useReducer(reducer, initialState);
const wsRef = useRef();

View File

@ -5,7 +5,7 @@ import JSMpeg from '@cycjimmy/jsmpeg-player';
export default function JSMpegPlayer({ camera, width, height }) {
const playerRef = useRef();
const url = `${baseUrl.replace(/^http/, 'ws')}/live/${camera}`;
const url = `${baseUrl.replace(/^http/, 'ws')}live/${camera}`;
useEffect(() => {
const video = new JSMpeg.VideoElement(