Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 22 additions & 0 deletions packages/hub/src/node/__tests__/initiate.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -184,6 +184,28 @@ describe('initHub', () => {
}
})

it('keeps a stripped proxy prefix when resolving the SSE path', async () => {
const hub = initHub({
base: DEVFRAMES_HUB_BASE,
auth: false,
devframes: [
makeFrame('alpha', makeDist('<title>alpha</title>')),
],
})
try {
for (const frame of ['', 'alpha/']) {
const metaPath = `${DEVFRAMES_HUB_BASE}${frame}__connection.json`
const response = await hub.handler(new Request(`http://localhost${metaPath}`))
const meta = await response.json()
expect(new URL(meta.sse.path, `http://localhost/foo${metaPath}`).pathname)
.toBe(`/foo${DEVFRAMES_HUB_BASE}__sse`)
}
}
finally {
await hub.close()
}
})

it('ui slot: viewer owns the root, embedded.js serves the entry, discovery still wins', async () => {
const viewerDist = makeDist('<!doctype html><title>hub viewer</title>')
const embeddedDir = mkdtempSync(join(tmpdir(), 'hub-embedded-'))
Expand Down
19 changes: 16 additions & 3 deletions packages/hub/src/node/initiate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ import { createInteractiveAuth } from 'devframe/recipes/interactive-auth'
import { mountStaticHandler } from 'devframe/utils/serve-static'
import { joinURL, withoutLeadingSlash } from 'devframe/utils/url'
import { H3 } from 'h3'
import { resolve } from 'pathe'
import { relative, resolve } from 'pathe'
import { DEVFRAMES_HUB_BASE, DOCK_RENDERERS_STATE_KEY, normalizeHubBase } from '../constants'
import { mountDevframes, renderClientImportsModule, resolveDevframesInput, resolveRendererRegistrations } from './assemble'
import { createHubContext } from './context'
Expand Down Expand Up @@ -342,6 +342,19 @@ export interface HubInstance {
close: () => Promise<void>
}

/** Resolve SSE from the metadata directory so proxy prefixes stay intact. */
function withRelativeSsePath(meta: ConnectionMeta | undefined, base: string): ConnectionMeta | undefined {
if (typeof meta?.sse !== 'object' || !meta.sse.path)
return meta
return {
...meta,
sse: {
...meta.sse,
path: relative(base, meta.sse.path),
},
}
}

/**
* Resolve the shared hub context: reuse a caller-supplied one, or build an
* h3-backed context that serves the hub's connection meta under every frame.
Expand Down Expand Up @@ -378,7 +391,7 @@ async function resolveHubContext(
* matter how deep the frame base is.
*/
mountConnectionMeta: (frameBase: string) => {
app.use(joinURL(frameBase, DEVFRAME_CONNECTION_META_FILENAME), () => api.connectionMeta())
app.use(joinURL(frameBase, DEVFRAME_CONNECTION_META_FILENAME), () => withRelativeSsePath(api.connectionMeta(), frameBase))
},
}
return createHubContext({
Expand Down Expand Up @@ -562,7 +575,7 @@ export function initHub(options: InitHubOptions): HubInstance {

// Hub-level discovery endpoints, registered before the viewer's static
// mount so its SPA-fallback can't swallow them.
app.use(joinURL(base, DEVFRAME_CONNECTION_META_FILENAME), () => meta)
app.use(joinURL(base, DEVFRAME_CONNECTION_META_FILENAME), () => withRelativeSsePath(meta, base))

const indexDocument = (): Record<string, unknown> => ({
name: options.name,
Expand Down
Loading