@hamedb89/localghost 0.1.0 → 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
@@ -8,8 +8,10 @@ Buh. Friendly local hostnames for app repos.
8
8
 
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
+ [![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.6-CB3837?logo=npm)](https://www.npmjs.com/package/@hamedb89/localghost)
11
13
 
12
- 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.
13
15
 
14
16
  [Website](https://hamedb89.github.io/localghost/) · [npm](https://www.npmjs.com/package/@hamedb89/localghost) · [GitHub](https://github.com/hamedb89/localghost)
15
17
 
@@ -18,9 +20,10 @@ Localghost is a tiny Node.js CLI for local HTTPS domains in app repos. It gives
18
20
  - Creates and reads `.localghost` in your app repo.
19
21
  - Lets repos choose explicit config files or filename patterns when `.localghost` is not enough.
20
22
  - Updates only a managed Localghost block in `/etc/hosts` during explicit setup.
21
- - 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`.
22
24
  - Checks whether Caddy is installed, but does not run Homebrew for you.
23
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.
24
27
  - Prints parsed config and project-local state as JSON for scripts, Codex, agents, and future MCP tools.
25
28
  - Checks npm for newer Localghost releases at most once per day, with an explicit opt-out.
26
29
 
@@ -81,12 +84,31 @@ First time on a machine:
81
84
  yarn localghost:setup
82
85
  ```
83
86
 
87
+ Check that the hosts block and Caddyfile are ready:
88
+
89
+ ```sh
90
+ yarn localghost:ready
91
+ ```
92
+
84
93
  Daily proxy:
85
94
 
86
95
  ```sh
87
96
  yarn localghost:proxy
88
97
  ```
89
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
+
90
112
  Prefer `.localhost` names. `.local` is supported, but Localghost warns because `.local` can collide with mDNS/Bonjour.
91
113
 
92
114
  ## Config Files
@@ -121,12 +143,19 @@ The Vite plugin accepts the same shape through `fileName`, `configFiles`, or `co
121
143
  "scripts": {
122
144
  "localghost:setup": "localghost setup",
123
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",
124
150
  "localghost:print": "localghost print",
125
151
  "localghost:routes": "localghost routes",
126
152
  "localghost:status": "localghost status",
153
+ "localghost:reset": "localghost reset",
127
154
  "localghost:teardown": "localghost teardown",
128
155
  "localghost:doctor": "localghost doctor",
129
- "localghost:update": "localghost update"
156
+ "localghost:update": "localghost update",
157
+ "caddy:setup": "localghost setup",
158
+ "caddy:dev": "localghost dev"
130
159
  }
131
160
  }
132
161
  ```
@@ -136,13 +165,50 @@ A full app might compose them with its own servers:
136
165
  ```json
137
166
  {
138
167
  "scripts": {
139
- "dev:web": "vite --host 127.0.0.1 --port 5173 --strictPort",
140
- "dev:api": "wrangler dev --port 8787",
141
- "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"
142
171
  }
143
172
  }
144
173
  ```
145
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
+
146
212
  ## Vite
147
213
 
148
214
  ```ts
@@ -153,26 +219,27 @@ export default defineConfig({
153
219
  plugins: [
154
220
  localGhostPlugin({
155
221
  port: 5173,
156
- https: true,
222
+ dynamicPort: true,
157
223
  configFiles: [".localghost.private", ".localghost"]
158
224
  })
159
225
  ]
160
226
  });
161
227
  ```
162
228
 
163
- 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.
164
232
 
165
233
  When Vite starts, Localghost prints the browser-facing URLs:
166
234
 
167
235
  ```txt
168
236
  localghost
169
- open: https://app.localhost/
170
- also: https://www.app.localhost/
237
+ local: http://app.localhost/
238
+ also: http://www.app.localhost/
171
239
  target: http://127.0.0.1:5173/
172
- proxy: Caddy local HTTPS
173
240
  ```
174
241
 
175
- `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.
176
243
 
177
244
  Set `log: false` if you want to keep Vite's default terminal output only.
178
245
 
@@ -185,17 +252,27 @@ localghost doctor
185
252
  localghost setup
186
253
  localghost setup --project app
187
254
  localghost setup --config .localghost.preview
255
+ localghost setup --https
188
256
  localghost status
257
+ localghost status --ready
258
+ localghost ps
259
+ localghost ps --json
260
+ localghost reset
189
261
  localghost teardown
190
262
  localghost teardown --remove-caddyfile
191
263
  localghost update
192
264
  localghost --no-update-check doctor
265
+ localghost run -- vite
266
+ localghost run --dynamic-port -- turbo dev
193
267
  localghost dev --config-pattern '^\.localghost\.'
268
+ localghost dev --https
194
269
  localghost print
195
270
  ```
196
271
 
197
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.
198
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
+
199
276
  `setup` writes only a managed block in the system hosts file:
200
277
 
201
278
  ```txt
@@ -208,19 +285,29 @@ Localghost does not rewrite the whole hosts file. It replaces only its own manag
208
285
 
209
286
  ## Teardown And State
210
287
 
211
- `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.
212
289
 
213
290
  ```sh
214
291
  localghost status
292
+ localghost status --ready
215
293
  localghost status --json
216
294
  ```
217
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
+
218
298
  When a project no longer needs Localghost, teardown removes only the managed hosts block for the selected project:
219
299
 
220
300
  ```sh
221
301
  localghost teardown
222
302
  ```
223
303
 
304
+ When you want to retest setup without deleting `.localghost`, use reset:
305
+
306
+ ```sh
307
+ localghost reset
308
+ localghost setup
309
+ ```
310
+
224
311
  The generated Caddyfile is left in place by default. Remove it explicitly when you want a fuller cleanup:
225
312
 
226
313
  ```sh