Update : server.cjs
This commit is contained in:
@@ -153,26 +153,45 @@ async function hubProxyFunc(req, res) {
|
|||||||
delete headersToSend.host;
|
delete headersToSend.host;
|
||||||
delete headersToSend.connection;
|
delete headersToSend.connection;
|
||||||
|
|
||||||
const proxyReq = new Request(externalURL, {
|
const response = await fetch(externalURL, {
|
||||||
method: req.method,
|
method: req.method,
|
||||||
headers: headersToSend,
|
headers: headersToSend,
|
||||||
body: req.method !== 'GET' && req.method !== 'HEAD' ? req : undefined,
|
body: req.method !== 'GET' && req.method !== 'HEAD' ? req : undefined,
|
||||||
duplex: 'half'
|
redirect: 'manual'
|
||||||
});
|
});
|
||||||
|
|
||||||
const response = await fetch(proxyReq);
|
|
||||||
|
|
||||||
for (const [key, value] of response.headers.entries()) {
|
for (const [key, value] of response.headers.entries()) {
|
||||||
res.setHeader(key, value);
|
res.setHeader(key, value);
|
||||||
}
|
}
|
||||||
res.status(response.status);
|
res.status(response.status);
|
||||||
|
|
||||||
|
if (response.status >= 300 && response.status < 400) {
|
||||||
|
// Redirect handling (due to ‘/redirect/docs/lua’)
|
||||||
|
const redirectUrl = response.headers.get('location');
|
||||||
|
if (redirectUrl) {
|
||||||
|
|
||||||
|
if (redirectUrl.startsWith('http')) {
|
||||||
|
|
||||||
|
if (redirectUrl.startsWith(hubURL)) {
|
||||||
|
const newPath = redirectUrl.replace(hubURL, '/hub-proxy');
|
||||||
|
res.setHeader('location', newPath);
|
||||||
|
}
|
||||||
|
|
||||||
|
} else if (redirectUrl.startsWith('/')) {
|
||||||
|
|
||||||
|
res.setHeader('location', `/hub-proxy${redirectUrl}`);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return res.end();
|
||||||
|
}
|
||||||
|
|
||||||
await pipeline(response.body, res);
|
await pipeline(response.body, res);
|
||||||
|
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error("[Hub Proxy] Error:", error);
|
console.error("[Hub Proxy] Error:", error);
|
||||||
if (!res.headersSent) {
|
if (!res.headersSent) {
|
||||||
res.status(502).send({ error: 'Proxy request failed' });
|
res.status(502).send({ error: 'Proxy request failed: ' + error.message });
|
||||||
} else {
|
} else {
|
||||||
res.end();
|
res.end();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -72,7 +72,7 @@
|
|||||||
</script>
|
</script>
|
||||||
|
|
||||||
<svelte:window onmessage={async (e) => {
|
<svelte:window onmessage={async (e) => {
|
||||||
if(e.origin.startsWith("https://sv.risuai.xyz") || e.origin.startsWith("http://127.0.0.1")){
|
if(e.origin.startsWith("https://sv.risuai.xyz") || e.origin.startsWith("http://127.0.0.1") || e.origin === window.location.origin){
|
||||||
if(e.data.msg.data.vaild && $alertStore.type === 'login'){
|
if(e.data.msg.data.vaild && $alertStore.type === 'login'){
|
||||||
$alertStore = {
|
$alertStore = {
|
||||||
type: 'none',
|
type: 'none',
|
||||||
|
|||||||
@@ -19,7 +19,7 @@
|
|||||||
</script>
|
</script>
|
||||||
|
|
||||||
<svelte:window onmessage={async (e) => {
|
<svelte:window onmessage={async (e) => {
|
||||||
if(e.origin.startsWith("https://sv.risuai.xyz") || e.origin.startsWith("http://127.0.0.1")){
|
if(e.origin.startsWith("https://sv.risuai.xyz") || e.origin.startsWith("http://127.0.0.1") || e.origin === window.location.origin){
|
||||||
if(e.data.msg.type === 'drive'){
|
if(e.data.msg.type === 'drive'){
|
||||||
await loadRisuAccountData()
|
await loadRisuAccountData()
|
||||||
DBState.db.account.data.refresh_token = e.data.msg.data.refresh_token
|
DBState.db.account.data.refresh_token = e.data.msg.data.refresh_token
|
||||||
|
|||||||
Reference in New Issue
Block a user