Possibly fix websocket connection via craco in dev mode

Signed-off-by: James Ketrenos <james_git@ketrenos.com>
This commit is contained in:
James Ketr 2023-01-18 09:46:31 -08:00
parent 0043480ff8
commit 99d8c927ee
5 changed files with 829 additions and 383 deletions

9
client/craco.config.js Normal file
View File

@ -0,0 +1,9 @@
module.exports = {
devServer: devServerConfig => {
devServerConfig.webSocketServer = {
options: { path: process.env.PUBLIC_URL + 'ws' }
};
return devServerConfig;
}
};

1150
client/package-lock.json generated

File diff suppressed because it is too large Load Diff

View File

@ -14,15 +14,16 @@
"react": "^18.2.0", "react": "^18.2.0",
"react-dom": "^18.2.0", "react-dom": "^18.2.0",
"react-resizable-panels": "^0.0.34", "react-resizable-panels": "^0.0.34",
"react-router-dom": "^6.6.2",
"react-scripts": "5.0.1", "react-scripts": "5.0.1",
"typescript": "^4.9.4", "typescript": "^4.9.4",
"web-vitals": "^2.1.4" "web-vitals": "^2.1.4"
}, },
"scripts": { "scripts": {
"start": "export $(cat .env | xargs) ; react-scripts start", "start": "export $(cat .env | xargs) ; craco start",
"build": "export $(cat .env | xargs) ; react-scripts build", "build": "export $(cat .env | xargs) ; craco build",
"test": "export $(cat .env | xargs) ; react-scripts test", "test": "export $(cat .env | xargs) ; craco test",
"eject": "export $(cat .env | xargs) ; react-scripts eject" "eject": "export $(cat .env | xargs) ; craco eject"
}, },
"eslintConfig": { "eslintConfig": {
"extends": [ "extends": [
@ -41,5 +42,8 @@
"last 1 firefox version", "last 1 firefox version",
"last 1 safari version" "last 1 safari version"
] ]
},
"devDependencies": {
"@craco/craco": "^7.0.0"
} }
} }

View File

@ -2,8 +2,16 @@
import React, { useState, useMemo, useEffect, useRef } from 'react'; import React, { useState, useMemo, useEffect, useRef } from 'react';
import { useApi } from './useApi'; import { useApi } from './useApi';
import { Panel, PanelGroup, PanelResizeHandle } from "react-resizable-panels"; import { Panel, PanelGroup, PanelResizeHandle } from "react-resizable-panels";
import {
BrowserRouter as Router,
Route,
Routes,
useParams
} from "react-router-dom";
import './App.css'; import './App.css';
const base = process.env.PUBLIC_URL; /* /identities -- set in .env */
const makeFaceBoxes = (photo: any, dimensions: any): any => { const makeFaceBoxes = (photo: any, dimensions: any): any => {
const faces: FaceData[] = photo.faces; const faces: FaceData[] = photo.faces;
@ -69,7 +77,7 @@ const Photo = ({ photoId }: any) => {
} }
const fetchImageData = async (image: number) => { const fetchImageData = async (image: number) => {
console.log(`Loading photo ${image}`); console.log(`Loading photo ${image}`);
const res = await window.fetch(`../api/v1/photos/${image}`); const res = await window.fetch(`${base}/api/v1/photos/${image}`);
const photo = await res.json(); const photo = await res.json();
setImage(photo); setImage(photo);
}; };
@ -252,7 +260,7 @@ interface IdentitiesProps {
const Identities = ({ identities, setIdentity } : IdentitiesProps) => { const Identities = ({ identities, setIdentity } : IdentitiesProps) => {
const identitiesJSX = useMemo(() => { const identitiesJSX = useMemo(() => {
const loadIdentity = async (id: number) => { const loadIdentity = async (id: number) => {
const res = await window.fetch(`../api/v1/identities/${id}`); const res = await window.fetch(`${base}/api/v1/identities/${id}`);
const data = await res.json(); const data = await res.json();
setIdentity(data[0]); setIdentity(data[0]);
}; };
@ -289,9 +297,12 @@ const App = () => {
const [identity, setIdentity] = useState<any>(undefined); const [identity, setIdentity] = useState<any>(undefined);
const [image, setImage] = useState<number>(0); const [image, setImage] = useState<number>(0);
const { loading, data } = useApi( const { loading, data } = useApi(
'../api/v1/identities' `${base}/api/v1/identities`
); );
const [selected, setSelected] = useState<number[]>([]); const [selected, setSelected] = useState<number[]>([]);
const { identityId, faceId } = useParams();
console.log({ identityId, faceId});
useEffect(() => { useEffect(() => {
if (data && data.length) { if (data && data.length) {
@ -302,7 +313,7 @@ const App = () => {
const removeSelected = async () => { const removeSelected = async () => {
try { try {
const res = await window.fetch( const res = await window.fetch(
`../api/v1/identities/faces/remove/${identity.id}`, { `${base}/api/v1/identities/faces/remove/${identity.id}`, {
method: 'PUT', method: 'PUT',
headers: { 'Content-Type': 'application/json' }, headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({ faces: selected }) body: JSON.stringify({ faces: selected })
@ -355,4 +366,14 @@ const App = () => {
); );
} }
export default App; const AppRouter = () => {
return (
<Router>
<Routes>
<Route element={<App />} path={`${base}/:identityId?/:faceId?`} />
</Routes>
</Router>
);
}
export default AppRouter;

View File

@ -9,6 +9,14 @@ location /identities {
proxy_pass_header P3P; proxy_pass_header P3P;
proxy_http_version 1.1; proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade; proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "upgrade"; proxy_set_header Connection "Upgrade";
proxy_pass https://localhost:3000; proxy_pass https://localhost:3000;
}
location /wsapp/ {
proxy_pass http://wsbackend;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "Upgrade";
proxy_set_header Host $host;
} }