File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 11{
2- "name" : " traccar" ,
2+ "name" : " @tang/ traccar" ,
33 "version" : " 6.5.0" ,
44 "type" : " module" ,
55 "private" : true ,
2121 "@vitejs/plugin-react" : " ^4.3.1" ,
2222 "dayjs" : " ^1.11.13" ,
2323 "events" : " ^3.3.0" ,
24+ "fetch-intercept" : " ^2.4.0" ,
2425 "mapbox-gl" : " ^1.13.3" ,
2526 "maplibre-gl" : " ^4.7.0" ,
2627 "maplibre-google-maps" : " ^1.1.0" ,
4041 "vite" : " ^5.4.6" ,
4142 "vite-plugin-pwa" : " ^0.20.5" ,
4243 "vite-plugin-svgr" : " ^4.2.0" ,
43- "wellknown" : " ^0.5.0"
44+ "wellknown" : " ^0.5.0" ,
45+ "whatwg-fetch" : " ^3.6.20"
4446 },
4547 "scripts" : {
4648 "start" : " vite" ,
4749 "build" : " vite build" ,
50+ "start:custom" : " VITE_SERVER_PROTOCOL=https: VITE_SERVER_URL=demo.traccar.org vite" ,
51+ "dev" : " npm run start:custom" ,
52+ "build:app" : " npm run start:custom build" ,
4853 "generate-pwa-assets" : " pwa-assets-generator --preset minimal public/logo.svg" ,
4954 "lint" : " eslint ." ,
5055 "lint:fix" : " eslint --fix ."
Original file line number Diff line number Diff line change @@ -33,8 +33,9 @@ const SocketController = () => {
3333 const features = useFeatures ( ) ;
3434
3535 const connectSocket = ( ) => {
36- const protocol = window . location . protocol === 'https:' ? 'wss:' : 'ws:' ;
37- const socket = new WebSocket ( `${ protocol } //${ window . location . host } /api/socket` ) ;
36+ const protocol = import . meta. env . VITE_SERVER_PROTOCOL ?? window . location . protocol === 'https:' ? 'wss:' : 'ws:' ;
37+ const host = import . meta. env . VITE_SERVER_URL ?? window . location . host ;
38+ const socket = new WebSocket ( `${ protocol } //${ host } /api/socket` ) ;
3839 socketRef . current = socket ;
3940
4041 socket . onopen = ( ) => {
Original file line number Diff line number Diff line change @@ -12,9 +12,29 @@ import NativeInterface from './common/components/NativeInterface';
1212import ServerProvider from './ServerProvider' ;
1313import ErrorBoundary from './ErrorBoundary' ;
1414import AppThemeProvider from './AppThemeProvider' ;
15+ import fetchIntercept from 'fetch-intercept' ;
1516
1617preloadImages ( ) ;
1718
19+ /** Setup API inteception */
20+ fetchIntercept . register ( {
21+ request : function ( url , config ) {
22+ const serverUrl = import . meta. env . VITE_SERVER_URL ;
23+ const apiUrl = url . length > 0 ? ( url . startsWith ( '/api' ) ? url : null ) : null ;
24+ if ( serverUrl && apiUrl ) {
25+ const serverProtocol = import . meta. env . VITE_SERVER_PROTOCOL ?? window . location . protocol ;
26+ url = `${ serverProtocol } //${ serverUrl } ${ url } `
27+ config = {
28+ ...config ,
29+ credentials : 'include' ,
30+ mode : 'cors' ,
31+ }
32+ }
33+
34+ return [ url , config ] ;
35+ } ,
36+ } ) ;
37+
1838const root = createRoot ( document . getElementById ( 'root' ) ) ;
1939root . render (
2040 < ErrorBoundary >
Original file line number Diff line number Diff line change 77import { useNavigate } from 'react-router-dom' ;
88import { useTranslation } from '../common/components/LocalizationProvider' ;
99
10- const currentServer = `${ window . location . protocol } //${ window . location . host } ` ;
10+ const protocol = import . meta. env . VITE_SERVER_PROTOCOL ?? window . location . protocol
11+ const serverUrl = import . meta. env . VITE_SERVER_URL ?? window . location . host ;
12+ const currentServer = `${ protocol } //${ serverUrl } ` ;
1113
1214const officialServers = [
1315 currentServer ,
Original file line number Diff line number Diff line change @@ -85,7 +85,9 @@ const EmulatorPage = () => {
8585 params . append ( 'id' , devices [ deviceId ] . uniqueId ) ;
8686 params . append ( 'lat' , latitude ) ;
8787 params . append ( 'lon' , longitude ) ;
88- response = await fetch ( `http://${ window . location . hostname } :5055?${ params . toString ( ) } ` , {
88+ const protocol = import . meta. env . VITE_SERVER_PROTOCOL ?? window . location . protocol
89+ const serverUrl = import . meta. env . VITE_SERVER_URL ?? window . location . host ;
90+ response = await fetch ( `${ protocol } //${ serverUrl } :5055?${ params . toString ( ) } ` , {
8991 method : 'POST' ,
9092 mode : 'no-cors' ,
9193 } ) ;
You can’t perform that action at this time.
0 commit comments