fix(api): show CloudFront distributions at <id>.cloudfront.localhost
CI / checks (pull_request) Successful in 26m17s

Distributions were linked under localhost.floci.io, another project's domain.
Every .localhost name resolves to the machine itself, so the brand-neutral
<id>.cloudfront.localhost reaches the runtime with no DNS or hosts entry.
This commit is contained in:
Zakaria
2026-10-24 14:25:35 -04:00
parent 9cb164f211
commit a86bee443b
3 changed files with 6 additions and 5 deletions
@@ -56,7 +56,7 @@ describe('AwsCdnAdapter distributions', () => {
const [listed] = await cdn.list() const [listed] = await cdn.list()
expect(listed).toMatchObject({id: ID, name: 'e7cpm0p0g0vc8d.cloudfront.net', status: 'Deployed'}) expect(listed).toMatchObject({id: ID, name: 'e7cpm0p0g0vc8d.cloudfront.net', status: 'Deployed'})
expect(listed.metadata).toMatchObject({viewerUrl: 'http://e7cpm0p0g0vc8d.cloudfront.localhost.floci.io:4566/', enabled: true, comment: 'Docs site', originDomains: ['site.s3.amazonaws.com']}) expect(listed.metadata).toMatchObject({viewerUrl: 'http://e7cpm0p0g0vc8d.cloudfront.localhost:4566/', enabled: true, comment: 'Docs site', originDomains: ['site.s3.amazonaws.com']})
expect(await cdn.list({search: 'site.s3'})).toHaveLength(1) expect(await cdn.list({search: 'site.s3'})).toHaveLength(1)
expect(await cdn.list({search: 'nothing'})).toHaveLength(0) expect(await cdn.list({search: 'nothing'})).toHaveLength(0)
}) })
@@ -46,8 +46,9 @@ const RECENT_INVALIDATIONS = 5
* - `DeleteDistribution` refuses an enabled distribution with `DistributionNotDisabled` * - `DeleteDistribution` refuses an enabled distribution with `DistributionNotDisabled`
* (409), as on AWS, so delete disables it first. * (409), as on AWS, so delete disables it first.
* - A missing distribution is `NoSuchDistribution` with HTTP 404. * - A missing distribution is `NoSuchDistribution` with HTTP 404.
* - Viewer requests reach a distribution at `{id}.cloudfront.localhost.floci.io` on the * - Viewer requests reach a distribution at `{id}.cloudfront.localhost` on the runtime's
* runtime's port, a name that resolves to 127.0.0.1 without any hosts-file entry. * port. Browsers and curl resolve every `.localhost` name to the machine itself (RFC 6761),
* so no DNS or hosts-file entry is needed.
*/ */
export class AwsCdnAdapter implements CloudServiceAdapter { export class AwsCdnAdapter implements CloudServiceAdapter {
readonly cloud = 'aws' as const readonly cloud = 'aws' as const
@@ -246,7 +247,7 @@ export class AwsCdnAdapter implements CloudServiceAdapter {
/** Where a browser on this machine reaches the distribution through the runtime. */ /** Where a browser on this machine reaches the distribution through the runtime. */
private viewerUrl(id: string): string { private viewerUrl(id: string): string {
const port = new URL(this.endpoint).port || '4566' const port = new URL(this.endpoint).port || '4566'
return `http://${id.toLowerCase()}.cloudfront.localhost.floci.io:${port}/` return `http://${id.toLowerCase()}.cloudfront.localhost:${port}/`
} }
} }
@@ -14,7 +14,7 @@ const api = vi.hoisted(() => ({
vi.mock('@/api/cloudProxyClient', () => api) vi.mock('@/api/cloudProxyClient', () => api)
vi.mock('@/lib/accountStore', () => ({useAccountId: () => '000000000000'})) vi.mock('@/lib/accountStore', () => ({useAccountId: () => '000000000000'}))
const VIEWER_URL = 'http://e7cpm0p0g0vc8d.cloudfront.localhost.floci.io:4566/' const VIEWER_URL = 'http://e7cpm0p0g0vc8d.cloudfront.localhost:4566/'
const distribution: CloudResource = { const distribution: CloudResource = {
id: 'E7CPM0P0G0VC8D', name: 'e7cpm0p0g0vc8d.cloudfront.net', cloud: 'aws', service: 'cdn', type: 'distribution', id: 'E7CPM0P0G0VC8D', name: 'e7cpm0p0g0vc8d.cloudfront.net', cloud: 'aws', service: 'cdn', type: 'distribution',
region: null, createdAt: null, status: 'Deployed', region: null, createdAt: null, status: 'Deployed',