From 21b1739148aea7b051bf7aa8d605c1148ed64c39 Mon Sep 17 00:00:00 2001 From: kjellbergzoey Date: Sun, 7 Jun 2026 20:05:58 +0000 Subject: [PATCH] feat: simplify local hostname to .lvh.me MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Drop the machine-name segment from project hostnames. Since lvh.me always resolves to 127.0.0.1, the per-machine segment added nothing but noise and made URLs ugly and hard to type/rewrite. before: http://my-theme.rasmus-macbook.lvh.me:5477 after: http://my-theme.lvh.me:5477 buildProjectHostname now returns .lvh.me (and ..lvh.me). getMachineHostname is kept — it's still used to stamp the host on db backups. Updated hostname and status tests accordingly. Co-Authored-By: Claude Opus 4.8 --- src/lib/hostname.ts | 5 +++-- tests/lib/hostname.test.ts | 20 +++++--------------- tests/lib/status.test.ts | 13 +++---------- 3 files changed, 11 insertions(+), 27 deletions(-) diff --git a/src/lib/hostname.ts b/src/lib/hostname.ts index 40f1330..e6e58e4 100644 --- a/src/lib/hostname.ts +++ b/src/lib/hostname.ts @@ -15,8 +15,9 @@ export function sanitizeHostname(raw: string): string { } export function buildProjectHostname(projectSlug: string, subdomain?: string): string { - const machine = getMachineHostname(); - const base = `${projectSlug}.${machine}.lvh.me`; + // lvh.me always resolves to 127.0.0.1, so the project slug alone is enough + // for a unique, easy-to-type local hostname — no machine segment needed. + const base = `${projectSlug}.lvh.me`; if (subdomain) { return `${subdomain}.${base}`; } diff --git a/tests/lib/hostname.test.ts b/tests/lib/hostname.test.ts index bdd5380..ba1edcc 100644 --- a/tests/lib/hostname.test.ts +++ b/tests/lib/hostname.test.ts @@ -1,14 +1,6 @@ -import os from 'node:os'; -import {describe, expect, it, vi} from 'vitest'; +import {describe, expect, it} from 'vitest'; import {buildProjectHostname, sanitizeHostname} from '../../src/lib/hostname.js'; -vi.mock('node:os', () => ({ - default: {hostname: vi.fn()}, - hostname: vi.fn(), -})); - -const mockHostname = vi.mocked(os.hostname); - describe('sanitizeHostname', () => { it('lowercases and strips .local suffix', () => { expect(sanitizeHostname('Rasmus-MacBook.local')).toBe('rasmus-macbook'); @@ -28,15 +20,13 @@ describe('sanitizeHostname', () => { }); describe('buildProjectHostname', () => { - it('combines project slug with machine hostname', () => { - mockHostname.mockReturnValue('rasmus-macbook.local'); - expect(buildProjectHostname('my-theme')).toBe('my-theme.rasmus-macbook.lvh.me'); + it('uses the project slug directly under lvh.me', () => { + expect(buildProjectHostname('my-theme')).toBe('my-theme.lvh.me'); }); - it('builds phpmyadmin subdomain', () => { - mockHostname.mockReturnValue('rasmus-macbook.local'); + it('builds a phpmyadmin subdomain', () => { expect(buildProjectHostname('my-theme', 'phpmyadmin')).toBe( - 'phpmyadmin.my-theme.rasmus-macbook.lvh.me', + 'phpmyadmin.my-theme.lvh.me', ); }); }); diff --git a/tests/lib/status.test.ts b/tests/lib/status.test.ts index 5019429..619502e 100644 --- a/tests/lib/status.test.ts +++ b/tests/lib/status.test.ts @@ -10,13 +10,6 @@ import { } from '../../src/lib/status.js'; import type {ProjectConfig} from '../../src/types/config.js'; -// buildProjectHostname embeds the machine hostname; pin it so URL assertions -// are deterministic regardless of the host the test runs on. -vi.mock('node:os', async (importOriginal) => { - const actual = await importOriginal(); - return {...actual, default: {...actual, hostname: () => 'testbox'}}; -}); - const PROJECT: ProjectConfig = { project_id: 'proj-123', name: 'acme', @@ -78,9 +71,9 @@ describe('getProjectStatus', () => { {name: 'proj-123-phpmyadmin', running: true}, ]); expect(status.urls).toEqual({ - site: 'http://acme.testbox.lvh.me:5477', - admin: 'http://acme.testbox.lvh.me:5477/wp-admin', - phpmyadmin: 'http://phpmyadmin.acme.testbox.lvh.me:5477', + site: 'http://acme.lvh.me:5477', + admin: 'http://acme.lvh.me:5477/wp-admin', + phpmyadmin: 'http://phpmyadmin.acme.lvh.me:5477', }); });