Skip to content

Commit 6602368

Browse files
dalkiaclaude
andcommitted
fix: rewrite {version}/assets/ requests to the sidecar's flat assets/ lane
Explorer requests v49+ scene bundles by their digest-bearing file name under the CDN's shared {version}/assets/ prefix (unity-explorer#9442). abgen serves those files through its flat /assets/{file} lane (bundle-index lookup) but has no version-prefixed route, so the proxy strips the version segment on the way through. Drop once abgen serves GET /{version}/assets/{file} natively. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
1 parent fccab14 commit 6602368

2 files changed

Lines changed: 23 additions & 1 deletion

File tree

packages/@dcl/sdk-commands/src/commands/start/server/asset-bundles-proxy.ts

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,17 @@ export function setupAssetBundlesProxy(
3939
delete requestHeaders['content-length']
4040
delete requestHeaders['accept-encoding']
4141

42-
const response = await components.fetch.fetch(`${sidecarUrl}/${ctx.params.path}${ctx.url.search}`, {
42+
// The route pattern types :path+ as string[], but the runtime hands it over as one string.
43+
const rawPath = Array.isArray(ctx.params.path) ? ctx.params.path.join('/') : ctx.params.path
44+
45+
// Explorer requests v49+ scene bundles by their digest-bearing file name under the
46+
// CDN's shared {version}/assets/ prefix (unity-explorer#9442). The sidecar serves
47+
// those same files through its flat /assets/{file} lane (bundle-index lookup) but
48+
// has no version-prefixed route, so strip the version segment on the way through.
49+
// TODO: drop once abgen serves GET /{version}/assets/{file} natively.
50+
const path = rawPath.replace(/^v\d+\/assets\//, 'assets/')
51+
52+
const response = await components.fetch.fetch(`${sidecarUrl}/${path}${ctx.url.search}`, {
4353
headers: requestHeaders,
4454
method,
4555
body: method === 'GET' || method === 'HEAD' ? undefined : (ctx.request.body as any),

test/sdk-commands/commands/start/asset-bundles-proxy.spec.ts

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,18 @@ describe('start/server/asset-bundles-proxy', () => {
6868
await expect(readBody(response.body)).resolves.toBe('bundle-bytes')
6969
})
7070

71+
it('rewrites the version-prefixed assets/ shape to the flat assets/ lane the sidecar serves', async () => {
72+
const { fetch, dispatch } = makeProxy(() => 'http://127.0.0.1:53211')
73+
fetch.mockResolvedValue(new Response('bundle-bytes', { status: 200 }))
74+
75+
await dispatch('GET', 'v49/assets/b64-abc_7580fefaf1c77b8b771687a8a4f86063_mac')
76+
77+
expect(fetch).toHaveBeenCalledWith(
78+
'http://127.0.0.1:53211/assets/b64-abc_7580fefaf1c77b8b771687a8a4f86063_mac',
79+
expect.anything()
80+
)
81+
})
82+
7183
it('forwards non-GET methods with their body and the sidecar status', async () => {
7284
const { fetch, dispatch } = makeProxy(() => 'http://127.0.0.1:53211')
7385
fetch.mockResolvedValue(new Response('nope', { status: 404 }))

0 commit comments

Comments
 (0)