@hamedb89/localghost 0.1.3 → 0.1.6

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -9,9 +9,9 @@ Buh. Friendly local hostnames for app repos.
9
9
  [![CI](https://github.com/hamedb89/localghost/actions/workflows/ci.yml/badge.svg)](https://github.com/hamedb89/localghost/actions/workflows/ci.yml)
10
10
  [![GitHub Pages](https://github.com/hamedb89/localghost/actions/workflows/pages.yml/badge.svg)](https://github.com/hamedb89/localghost/actions/workflows/pages.yml)
11
11
  [![Publish npm](https://github.com/hamedb89/localghost/actions/workflows/publish-npm.yml/badge.svg)](https://github.com/hamedb89/localghost/actions/workflows/publish-npm.yml)
12
- [![npm version](https://img.shields.io/badge/npm-v0.1.3-CB3837?logo=npm)](https://www.npmjs.com/package/@hamedb89/localghost)
12
+ [![npm version](https://img.shields.io/badge/npm-v0.1.6-CB3837?logo=npm)](https://www.npmjs.com/package/@hamedb89/localghost)
13
13
 
14
- Localghost is a tiny Node.js CLI for local HTTPS domains in app repos. It gives each project one small contract for `.localhost` hostnames, Caddy reverse proxies, Vite `allowedHosts`, and the system hosts file, so developers can open `https://app.localhost/` instead of remembering which localhost port belongs to which process.
14
+ Localghost is a tiny Node.js CLI for friendly local domains in app repos. It gives each project one small contract for `.localhost` hostnames, Caddy reverse proxies, Vite `allowedHosts`, and the system hosts file, so developers can open `http://app.localhost/` instead of remembering which localhost port belongs to which process.
15
15
 
16
16
  [Website](https://hamedb89.github.io/localghost/) · [npm](https://www.npmjs.com/package/@hamedb89/localghost) · [GitHub](https://github.com/hamedb89/localghost)
17
17
 
@@ -20,9 +20,10 @@ Localghost is a tiny Node.js CLI for local HTTPS domains in app repos. It gives
20
20
  - Creates and reads `.localghost` in your app repo.
21
21
  - Lets repos choose explicit config files or filename patterns when `.localghost` is not enough.
22
22
  - Updates only a managed Localghost block in `/etc/hosts` during explicit setup.
23
- - Generates `ops/local/Caddyfile` for local HTTPS reverse proxying.
23
+ - Generates `ops/local/Caddyfile` for local reverse proxying. HTTP is the default; HTTPS is explicit with `--https` or `--ssl`.
24
24
  - Checks whether Caddy is installed, but does not run Homebrew for you.
25
25
  - Provides a Vite plugin that sets explicit `server.allowedHosts` entries.
26
+ - Defaults Vite dev to the configured Localghost domain and no-ops during production/build.
26
27
  - Prints parsed config and project-local state as JSON for scripts, Codex, agents, and future MCP tools.
27
28
  - Checks npm for newer Localghost releases at most once per day, with an explicit opt-out.
28
29
 
@@ -83,12 +84,31 @@ First time on a machine:
83
84
  yarn localghost:setup
84
85
  ```
85
86
 
87
+ Check that the hosts block and Caddyfile are ready:
88
+
89
+ ```sh
90
+ yarn localghost:ready
91
+ ```
92
+
86
93
  Daily proxy:
87
94
 
88
95
  ```sh
89
96
  yarn localghost:proxy
90
97
  ```
91
98
 
99
+ Use HTTPS only when you explicitly want Caddy local certificates:
100
+
101
+ ```sh
102
+ yarn localghost:proxy:https
103
+ ```
104
+
105
+ Reset generated setup without deleting `.localghost`:
106
+
107
+ ```sh
108
+ yarn localghost:reset
109
+ yarn localghost:setup
110
+ ```
111
+
92
112
  Prefer `.localhost` names. `.local` is supported, but Localghost warns because `.local` can collide with mDNS/Bonjour.
93
113
 
94
114
  ## Config Files
@@ -123,12 +143,19 @@ The Vite plugin accepts the same shape through `fileName`, `configFiles`, or `co
123
143
  "scripts": {
124
144
  "localghost:setup": "localghost setup",
125
145
  "localghost:proxy": "localghost dev",
146
+ "localghost:proxy:https": "localghost dev --https",
147
+ "localghost:run": "localghost run --",
148
+ "localghost:ready": "localghost status --ready",
149
+ "localghost:ps": "localghost ps",
126
150
  "localghost:print": "localghost print",
127
151
  "localghost:routes": "localghost routes",
128
152
  "localghost:status": "localghost status",
153
+ "localghost:reset": "localghost reset",
129
154
  "localghost:teardown": "localghost teardown",
130
155
  "localghost:doctor": "localghost doctor",
131
- "localghost:update": "localghost update"
156
+ "localghost:update": "localghost update",
157
+ "caddy:setup": "localghost setup",
158
+ "caddy:dev": "localghost dev"
132
159
  }
133
160
  }
134
161
  ```
@@ -138,13 +165,50 @@ A full app might compose them with its own servers:
138
165
  ```json
139
166
  {
140
167
  "scripts": {
141
- "dev:web": "vite --host 127.0.0.1 --port 5173 --strictPort",
142
- "dev:api": "wrangler dev --port 8787",
143
- "dev:local": "concurrently -k \"npm run dev:web\" \"npm run dev:api\" \"npm run localghost:proxy\""
168
+ "dev": "localghost run -- vite",
169
+ "dev:dynamic": "localghost run --dynamic-port -- vite",
170
+ "dev:raw": "vite"
144
171
  }
145
172
  }
146
173
  ```
147
174
 
175
+ In Turborepo, let Localghost wrap the dev runner and keep dev uncached:
176
+
177
+ ```json
178
+ {
179
+ "scripts": {
180
+ "dev": "localghost run --dynamic-port -- turbo dev",
181
+ "dev:raw": "turbo dev"
182
+ }
183
+ }
184
+ ```
185
+
186
+ Then keep persistent dev tasks uncached:
187
+
188
+ ```json
189
+ {
190
+ "tasks": {
191
+ "dev": { "cache": false, "persistent": true }
192
+ }
193
+ }
194
+ ```
195
+
196
+ `localghost run` resolves one shared Localghost context, starts Caddy, passes the selected port to the child command through `LOCALGHOST_PORT` and `VITE_PORT`, and stops Caddy when the child exits. With `--dynamic-port`, Localghost starts at the configured port, checks `127.0.0.1:<port>`, and walks upward until it finds a free port.
197
+
198
+ `localghost dev` and `localghost run` also register their active sessions in a user-local activity file. Use `localghost ps` to see the Localghost apps currently running on the machine:
199
+
200
+ ```txt
201
+ localghost ps
202
+
203
+ app run: vite
204
+ cwd: /Users/you/Projects/app
205
+ pid: 12345, caddy: 12346, child: 12347
206
+ started: 2026-07-05T12:00:00.000Z
207
+ app.localhost -> 127.0.0.1:5173 (listening)
208
+ ```
209
+
210
+ Pass `--json` when another helper, such as a menu bar app, needs to poll the same state.
211
+
148
212
  ## Vite
149
213
 
150
214
  ```ts
@@ -155,26 +219,27 @@ export default defineConfig({
155
219
  plugins: [
156
220
  localGhostPlugin({
157
221
  port: 5173,
158
- https: true,
222
+ dynamicPort: true,
159
223
  configFiles: [".localghost.private", ".localghost"]
160
224
  })
161
225
  ]
162
226
  });
163
227
  ```
164
228
 
165
- The plugin generates an explicit `server.allowedHosts` list from the selected config file; it does not set `allowedHosts: true`.
229
+ The plugin binds Vite to `127.0.0.1` by default, prints the selected Localghost domain, generates an explicit `server.allowedHosts` list from the selected config file, and does not set `allowedHosts: true`. It runs only during local `vite serve`; production/build mode no-ops. When `dynamicPort` is enabled, the plugin uses the configured port when available and otherwise moves to the next free port before Vite starts.
230
+
231
+ If `.localghost` is missing and Vite is running in an interactive terminal, the plugin asks whether to create one, prompts for the primary domain and optional extra domains, and then asks whether to run setup. Before touching `/etc/hosts`, it explains why macOS may ask for your password and confirms that only Localghost's managed block is changed.
166
232
 
167
233
  When Vite starts, Localghost prints the browser-facing URLs:
168
234
 
169
235
  ```txt
170
236
  localghost
171
- open: https://app.localhost/
172
- also: https://www.app.localhost/
237
+ local: http://app.localhost/
238
+ also: http://www.app.localhost/
173
239
  target: http://127.0.0.1:5173/
174
- proxy: Caddy local HTTPS
175
240
  ```
176
241
 
177
- `https: true` means the browser-facing URL is expected to go through Caddy on HTTPS, while Vite still runs behind it on `127.0.0.1:<port>`. The plugin uses that to set Vite websocket/HMR proxy settings and to print `https://...` local host URLs.
242
+ `https: true` means the browser-facing URL is expected to go through Caddy on HTTPS, while Vite still runs behind it on `127.0.0.1:<port>`. The plugin uses that to set Vite websocket/HMR proxy settings and to print `https://...` local host URLs. Localghost never opens browser tabs by default.
178
243
 
179
244
  Set `log: false` if you want to keep Vite's default terminal output only.
180
245
 
@@ -187,17 +252,27 @@ localghost doctor
187
252
  localghost setup
188
253
  localghost setup --project app
189
254
  localghost setup --config .localghost.preview
255
+ localghost setup --https
190
256
  localghost status
257
+ localghost status --ready
258
+ localghost ps
259
+ localghost ps --json
260
+ localghost reset
191
261
  localghost teardown
192
262
  localghost teardown --remove-caddyfile
193
263
  localghost update
194
264
  localghost --no-update-check doctor
265
+ localghost run -- vite
266
+ localghost run --dynamic-port -- turbo dev
195
267
  localghost dev --config-pattern '^\.localghost\.'
268
+ localghost dev --https
196
269
  localghost print
197
270
  ```
198
271
 
199
272
  Localghost checks npm for newer releases after successful commands. The check has a short timeout, is cached for 24 hours, and never fails the command. Disable it with `LOCALGHOST_NO_UPDATE_CHECK=1` or `--no-update-check`. Run `localghost update` when you want an explicit update check.
200
273
 
274
+ `setup`, `dev`, and `teardown` refuse to run in production-like environments such as `NODE_ENV=production`, `VERCEL_ENV=production`, or `LOCALGHOST_ENV=production`.
275
+
201
276
  `setup` writes only a managed block in the system hosts file:
202
277
 
203
278
  ```txt
@@ -210,19 +285,29 @@ Localghost does not rewrite the whole hosts file. It replaces only its own manag
210
285
 
211
286
  ## Teardown And State
212
287
 
213
- `setup` writes a project-local state file at `ops/local/localghost-state.json`. It records the last Localghost action, selected config path, generated Caddyfile path, hosts file path, and the host entries that were applied. This is durable enough for project tooling and avoids relying on OS temp folders for tracking. Most apps should treat it as generated local state and ignore it in git.
288
+ `setup` writes a project-local state file at `ops/local/localghost-state.json`. It records the last Localghost action, selected config path, generated Caddyfile path, hosts file path, proxy mode, and the host entries that were applied. This is durable enough for project tooling and avoids relying on OS temp folders for tracking. Most apps should treat it as generated local state and ignore it in git.
214
289
 
215
290
  ```sh
216
291
  localghost status
292
+ localghost status --ready
217
293
  localghost status --json
218
294
  ```
219
295
 
296
+ `localghost dev` requires setup to be ready before it starts Caddy. If setup is missing or stale, it prints the exact `localghost setup` command instead of silently running `sudo`. Use `localghost dev --setup` only when you explicitly want the dev command to perform setup first.
297
+
220
298
  When a project no longer needs Localghost, teardown removes only the managed hosts block for the selected project:
221
299
 
222
300
  ```sh
223
301
  localghost teardown
224
302
  ```
225
303
 
304
+ When you want to retest setup without deleting `.localghost`, use reset:
305
+
306
+ ```sh
307
+ localghost reset
308
+ localghost setup
309
+ ```
310
+
226
311
  The generated Caddyfile is left in place by default. Remove it explicitly when you want a fuller cleanup:
227
312
 
228
313
  ```sh