Fix: Resolve Realm CORS Violation for Node.js Hosted Version (#814)

# PR Checklist
- [] Have you checked if it works normally in all models? *Ignore this
if it doesn't use models.*
   - Not applicable
- [] Have you checked if it works normally in all web, local, and node
hosted versions? If it doesn't, have you blocked it in those versions?
   - Done
- [] Have you added type definitions?
   - Not applicable

# Description
## Problem
The Node.js hosted version of RisuAI encountered an issue where it
failed to fetch data from the Risu Realm server when accessed remotely.

RisuAI's frontend directly fetches data from the Realm server (e.g.,
sv.risuai.xyz). While the official web version did not exhibit CORS
errors (potentially due to same-origin deployment or specific
server-side CORS configurations), running the Node.js version on a
self-hosted server and accessing it remotely resulted in browser CORS
policy violations.

## Solution
The fix involves detecting when the frontend runs in the Node.js host
environment.

When this environment is detected, instead of requesting Realm data
directly from the external server (sv.risuai.xyz), the frontend now
directs the request to a new proxy endpoint (`/hub-proxy/*`) on its own
backend server.

The backend proxy then fetches the required data (including JSON and
images) from the actual Realm server, correctly handles content types
and compression, and relays the response back to the frontend.

This ensures that, from the browser's perspective, the frontend is
communicating with its same-origin backend, effectively bypassing
browser CORS restrictions and resolving the data fetching issue.
This commit is contained in:
kwaroran
2025-04-14 14:07:10 +09:00
committed by GitHub
4 changed files with 141 additions and 25 deletions

View File

@@ -18,7 +18,11 @@ import { exportModule, readModule, type RisuModule } from "./process/modules"
import { readFile } from "@tauri-apps/plugin-fs"
import { onOpenUrl } from '@tauri-apps/plugin-deep-link';
export const hubURL = "https://sv.risuai.xyz"
const EXTERNAL_HUB_URL = 'https://sv.risuai.xyz';
export const hubURL = typeof window !== 'undefined' && (window as any).__NODE__ === true
? '/hub-proxy'
: EXTERNAL_HUB_URL;
export async function importCharacter() {
try {