dev-proxy: a stylesheet's url() is a URL
Two bugs, one line apart, both silent.
The `url(/…)` rule only matched an UNQUOTED target, so `url("/fonts/x.woff2")` — the form every
generator emits — went through untouched. And it only ran on HTML, so a linked stylesheet got the
narrow `/_bun/` rule and nothing else.
Together that meant a site's own @font-face rules kept pointing at `/fonts/…`, which inside the frame
is the platform's root. Every face 404'd and the preview rendered in a system fallback: nothing looked
broken, it just looked like a different site than the one being previewed.
JavaScript keeps the narrow rule — an absolute path in JS may not be a URL. In CSS it always is.
Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -1,7 +1,7 @@
|
||||
import { createRouter } from '../../create-router';
|
||||
import { resolveAuthToken } from '../../auth-token';
|
||||
import { isSuperAdmin } from '../../super-admin';
|
||||
import { rewriteAssetPaths, rewriteHtml } from './html-rewrite';
|
||||
import { rewriteAssetPaths, rewriteCss, rewriteHtml } from './html-rewrite';
|
||||
|
||||
/**
|
||||
* See a dev server running on THIS machine's loopback, from a browser that is somewhere else.
|
||||
@@ -145,7 +145,8 @@ devProxyRouter.all('/:port/*', async (ctx) => {
|
||||
|
||||
const type = res.headers.get('content-type') ?? '';
|
||||
const isHtml = type.includes('text/html');
|
||||
const rewritable = isHtml || type.includes('javascript') || type.includes('text/css');
|
||||
const isCss = type.includes('text/css');
|
||||
const rewritable = isHtml || isCss || type.includes('javascript');
|
||||
|
||||
const headers = new Headers(res.headers);
|
||||
// Anything framed here is the owner's own dev server; the platform frames it deliberately.
|
||||
@@ -169,7 +170,11 @@ devProxyRouter.all('/:port/*', async (ctx) => {
|
||||
}
|
||||
|
||||
const text = await res.text();
|
||||
const body = isHtml ? rewriteHtml(text, prefix) : rewriteAssetPaths(text, prefix);
|
||||
const body = isHtml
|
||||
? rewriteHtml(text, prefix)
|
||||
: isCss
|
||||
? rewriteCss(text, prefix)
|
||||
: rewriteAssetPaths(text, prefix);
|
||||
// Both are wrong after a rewrite: the length changed, and the body was decoded on the way through.
|
||||
headers.delete('content-length');
|
||||
headers.delete('content-encoding');
|
||||
|
||||
Reference in New Issue
Block a user