mirror of
https://github.com/djdevin/recflare.git
synced 2026-10-25 15:09:18 -07:00
[studio] beta studio (#114)
* rrs stuff * studio service yay * rrs whitelist * moree studiooooooo fellowwww * rec room studio room loading yay * fixes yay * fix 2 because idk yayuh * Update cdn.app.ts * ccontent length fix? * Preserve content-length and upgrade metadata Return a real zero-filled byte array for CDN HEAD responses so the runtime preserves Content-Length while still sending no payload. In notify, re-create the Request with its original headers, set OWNER_HEADER from the validated token, and forward that Request to hub.fetch to avoid losing WebSocket upgrade metadata (which could trigger 500s in Durable Objects). These changes ensure the editor's size checks and WebSocket upgrades remain reliable. * fix x524234 * shirt thing? * [auth] remove grant table as we already have audit_log for now * rename table to generic device_grant * cleanup/lint --------- Co-authored-by: Devin Zuczek <devin.zuczek@gmail.com>
This commit is contained in:
@@ -1,10 +1,30 @@
|
||||
import { cors } from 'hono/cors'
|
||||
|
||||
/** Default CORS handler */
|
||||
export function withDefaultCors() {
|
||||
return cors({
|
||||
origin: '*',
|
||||
allowMethods: ['GET', 'POST', 'PUT', 'PATCH', 'DELETE', 'OPTIONS', 'HEAD'],
|
||||
allowHeaders: ['Content-Type', 'Authorization'],
|
||||
})
|
||||
import type { MiddlewareHandler } from 'hono'
|
||||
|
||||
const preflight = cors({
|
||||
origin: '*',
|
||||
allowMethods: ['GET', 'POST', 'PUT', 'PATCH', 'DELETE', 'OPTIONS', 'HEAD'],
|
||||
allowHeaders: ['Content-Type', 'Authorization'],
|
||||
})
|
||||
|
||||
/**
|
||||
* Browser callers need `Access-Control-Allow-Origin`. Hono's `cors()` writes
|
||||
* that header before `next()`, which creates `c.res`. The route's Response is
|
||||
* then rebuilt with `new Response(body, res)`, and that rebuild drops
|
||||
* `encodeBody`. workerd removes `Content-Length` from a null body unless
|
||||
* `encodeBody` is `manual`, so a HEAD that reports a size lost the length.
|
||||
* Set the header after `next()` so the route's Response stays as it was.
|
||||
* OPTIONS still uses Hono's preflight response.
|
||||
*/
|
||||
export function withDefaultCors(): MiddlewareHandler {
|
||||
return async (c, next) => {
|
||||
if (c.req.method === 'OPTIONS') return preflight(c, next)
|
||||
if ((c.req.header('upgrade') ?? '').toLowerCase() === 'websocket') return next()
|
||||
try {
|
||||
await next()
|
||||
} finally {
|
||||
c.res.headers.set('Access-Control-Allow-Origin', '*')
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user