diff --git a/build/Dockerfile b/build/Dockerfile index 48e3c59..6bc42ee 100644 --- a/build/Dockerfile +++ b/build/Dockerfile @@ -6,5 +6,6 @@ RUN apk update && apk add nginx COPY ./dist/ /dashboard COPY ./build/nginx.conf /etc/nginx +COPY ./build/start.sh / -CMD nginx && /clash \ No newline at end of file +ENTRYPOINT [ "sh", "/start.sh" ] \ No newline at end of file diff --git a/build/nginx.conf b/build/nginx.conf index 81bbfa6..2441f60 100644 --- a/build/nginx.conf +++ b/build/nginx.conf @@ -19,6 +19,13 @@ http { root /dashboard; } + location /api { + rewrite ^/api(.*)$ $1 break; + proxy_set_header Upgrade $http_upgrade; + proxy_set_header Connection "upgrade"; + proxy_pass http://localhost:9090; + } + error_page 404 /404.html; error_page 500 502 503 504 /50x.html; } diff --git a/build/start.sh b/build/start.sh new file mode 100644 index 0000000..73cc143 --- /dev/null +++ b/build/start.sh @@ -0,0 +1,2 @@ +nginx +/clash \ No newline at end of file diff --git a/src/stores/jotai.ts b/src/stores/jotai.ts index 00f9a5e..bb7cae9 100644 --- a/src/stores/jotai.ts +++ b/src/stores/jotai.ts @@ -265,7 +265,7 @@ export function useLogsStreamReader () { if (level) { const apiInfo = apiInfoRef.current const protocol = apiInfo.protocol === 'http:' ? 'ws:' : 'wss:' - const logUrl = `${protocol}//${apiInfo.hostname}:${apiInfo.port}/logs?level=${level}&token=${encodeURIComponent(apiInfo.secret)}` + const logUrl = `${protocol}//${window.location.host}/api/logs?level=${level}&token=${encodeURIComponent(apiInfo.secret)}` item.connect(logUrl) } }, [apiInfoRef, item, level, previousKey]) @@ -279,7 +279,7 @@ export function useConnectionStreamReader () { const connection = useRef(new StreamReader({ bufferLength: 200 })) const protocol = apiInfo.protocol === 'http:' ? 'ws:' : 'wss:' - const url = `${protocol}//${apiInfo.hostname}:${apiInfo.port}/connections?token=${encodeURIComponent(apiInfo.secret)}` + const url = `${protocol}//${window.location.host}/api/connections?token=${encodeURIComponent(apiInfo.secret)}` useEffect(() => { connection.current.connect(url) diff --git a/src/stores/request.ts b/src/stores/request.ts index 59639eb..600ca96 100644 --- a/src/stores/request.ts +++ b/src/stores/request.ts @@ -91,20 +91,15 @@ const clientAtom = atom({ }) export function useClient () { - const { - hostname, - port, - secret, - protocol, - } = useAPIInfo() + const { secret } = useAPIInfo() const [item, setItem] = useAtom(clientAtom) - const key = `${protocol}//${hostname}:${port}?secret=${secret}` + const key = `/api?secret=${secret}` if (item.key === key) { return item.instance! } - const client = new Client(`${protocol}//${hostname}:${port}`, secret) + const client = new Client('/api', secret) setItem({ key, instance: client }) return client