Since Discord Activities run in a sandbox, any requests to external content (e.g. a game backend) must either be done as relative urls or explicitly prefixed with https://{CLIENT_ID}.discordsays.com/.proxy/. Svelcordot overrides window.fetch to automatically add that prefix to all requests.
However, this makes it impossible to access external apis from within Godot. Godot's HttpClient does not support relative urls. Attempting to request a relative url (e.g. /api/signup) throws an error because Godot cannot parse the url. The Discord documentation recommends to use absolute urls with the full prefix as a workaround in cases where relative urls are not possible. However, in that case, Svelcordot still adds the prefix, even though it is already there, turning the url into something like https://12345.discordsays.com/.proxy/https://12345.discordsays.com/.proxy/api/signup.
Additionally, if the server uses gzip encoding, the Content-Encoding: gzip header is still included in the response, but the body will already be decompressed when it arrives in Godot. I'm not sure if this is caused by the Discord proxy or by the window.fetch override, but it does cause Godot to throw another error because it cannot decompress the body.
I have made some local changes to /src/routes/+page.svelte to fix these issues (only add the prefix if it's not already there and remove any Content-Encoding headers). They do feel a bit hacky though and I'm not sure if there is a cleaner solution. Should I make a PR or is there a better way to solve this?
Since Discord Activities run in a sandbox, any requests to external content (e.g. a game backend) must either be done as relative urls or explicitly prefixed with
https://{CLIENT_ID}.discordsays.com/.proxy/
. Svelcordot overrideswindow.fetch
to automatically add that prefix to all requests.However, this makes it impossible to access external apis from within Godot. Godot's HttpClient does not support relative urls. Attempting to request a relative url (e.g.
/api/signup
) throws an error because Godot cannot parse the url. The Discord documentation recommends to use absolute urls with the full prefix as a workaround in cases where relative urls are not possible. However, in that case, Svelcordot still adds the prefix, even though it is already there, turning the url into something likehttps://12345.discordsays.com/.proxy/https://12345.discordsays.com/.proxy/api/signup
.Additionally, if the server uses gzip encoding, the
Content-Encoding: gzip
header is still included in the response, but the body will already be decompressed when it arrives in Godot. I'm not sure if this is caused by the Discord proxy or by the window.fetch override, but it does cause Godot to throw another error because it cannot decompress the body.I have made some local changes to
/src/routes/+page.svelte
to fix these issues (only add the prefix if it's not already there and remove any Content-Encoding headers). They do feel a bit hacky though and I'm not sure if there is a cleaner solution. Should I make a PR or is there a better way to solve this?