feat: Add instance changing

This commit is contained in:
Xyphyn committed 2023-07-02 14:27:04 -07:00
1 parent f201123291
commit 3159583654
17 files changed
+142 -35

No files matched your search

+26
View File
@@ -0,0 +1,26 @@
import { instance_url } from '$lib/lemmy.js'
export async function handle({ event, resolve }) {
// annoying hack to fix lemmy's CORS
if (event.url.pathname.startsWith('/cors')) {
const instance = `${event.url.pathname.split('/')[2]}`
const url = `${event.url.pathname
.split('/')
.slice(3)
.join('/')}?${event.url.searchParams.toString()}`
event.request.headers.delete('origin')
event.request.headers.delete('host')
const data = await fetch(`https://${instance}/${url.toString()}`, {
method: event.request.method,
body: event.request.body,
headers: event.request.headers,
})
return new Response(JSON.stringify(await data.json()))
}
const response = await resolve(event)
return response
}