增加启动脚本,反代9090端口api,反代ws

This commit is contained in:
LaoYutang 2023-05-28 20:58:25 +08:00
parent 65c1f42c9a
commit 4c6d6068eb
5 changed files with 16 additions and 11 deletions

View File

@ -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
ENTRYPOINT [ "sh", "/start.sh" ]

View File

@ -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;
}

2
build/start.sh Normal file
View File

@ -0,0 +1,2 @@
nginx
/clash

View File

@ -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<API.Snapshot>({ 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)

View File

@ -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