@hamedb89/localghost 0.1.0
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/LICENSE +21 -0
- package/README.md +278 -0
- package/assets/localghost-app-icon.png +0 -0
- package/assets/localghost-banner.png +0 -0
- package/assets/localghost-mascot.png +0 -0
- package/assets/localghost-wordmark.png +0 -0
- package/dist/cli.d.ts +1 -0
- package/dist/cli.js +804 -0
- package/dist/cli.js.map +1 -0
- package/dist/config-Cde1Bich.d.ts +31 -0
- package/dist/index.d.ts +132 -0
- package/dist/index.js +648 -0
- package/dist/index.js.map +1 -0
- package/dist/vite.d.ts +18 -0
- package/dist/vite.js +202 -0
- package/dist/vite.js.map +1 -0
- package/docs/brand.md +43 -0
- package/docs/flows.md +141 -0
- package/docs/github.md +129 -0
- package/docs/localghost.1.md +124 -0
- package/package.json +92 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Hamed Bahrami
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,278 @@
|
|
|
1
|
+
<p align="center">
|
|
2
|
+
<img src="./assets/localghost-banner.png" alt="Localghost - Friendly local hostnames" width="960">
|
|
3
|
+
</p>
|
|
4
|
+
|
|
5
|
+
# @hamedb89/localghost
|
|
6
|
+
|
|
7
|
+
Buh. Friendly local hostnames for app repos.
|
|
8
|
+
|
|
9
|
+
[](https://github.com/hamedb89/localghost/actions/workflows/ci.yml)
|
|
10
|
+
[](https://github.com/hamedb89/localghost/actions/workflows/pages.yml)
|
|
11
|
+
|
|
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.
|
|
13
|
+
|
|
14
|
+
[Website](https://hamedb89.github.io/localghost/) · [npm](https://www.npmjs.com/package/@hamedb89/localghost) · [GitHub](https://github.com/hamedb89/localghost)
|
|
15
|
+
|
|
16
|
+
## What It Does
|
|
17
|
+
|
|
18
|
+
- Creates and reads `.localghost` in your app repo.
|
|
19
|
+
- Lets repos choose explicit config files or filename patterns when `.localghost` is not enough.
|
|
20
|
+
- Updates only a managed Localghost block in `/etc/hosts` during explicit setup.
|
|
21
|
+
- Generates `ops/local/Caddyfile` for local HTTPS reverse proxying.
|
|
22
|
+
- Checks whether Caddy is installed, but does not run Homebrew for you.
|
|
23
|
+
- Provides a Vite plugin that sets explicit `server.allowedHosts` entries.
|
|
24
|
+
- Prints parsed config and project-local state as JSON for scripts, Codex, agents, and future MCP tools.
|
|
25
|
+
- Checks npm for newer Localghost releases at most once per day, with an explicit opt-out.
|
|
26
|
+
|
|
27
|
+
## Trust
|
|
28
|
+
|
|
29
|
+
- CI runs typecheck, build, site build, and npm package dry-run on Node 20 and 22.
|
|
30
|
+
- GitHub Pages is deployed by Actions from the checked-in `site/` and `assets/` sources.
|
|
31
|
+
- npm publish is guarded by `prepublishOnly` and the release workflow publishes with npm provenance.
|
|
32
|
+
- Runtime dependencies are intentionally small: `commander` for the CLI and `execa` for process execution. Vite is an optional peer dependency for the Vite plugin.
|
|
33
|
+
- No postinstall scripts, hidden Homebrew installs, or broad hosts-file rewrites.
|
|
34
|
+
- Update checks are best-effort, cached for 24 hours, and can be disabled with `LOCALGHOST_NO_UPDATE_CHECK=1` or `--no-update-check`.
|
|
35
|
+
|
|
36
|
+
<p align="center">
|
|
37
|
+
<img src="./assets/localghost-app-icon.png" alt="Localghost app icon" width="180">
|
|
38
|
+
</p>
|
|
39
|
+
|
|
40
|
+
## Install
|
|
41
|
+
|
|
42
|
+
```sh
|
|
43
|
+
yarn add -D @hamedb89/localghost
|
|
44
|
+
```
|
|
45
|
+
|
|
46
|
+
## Quick Start
|
|
47
|
+
|
|
48
|
+
Create the project config and optional package scripts:
|
|
49
|
+
|
|
50
|
+
```sh
|
|
51
|
+
yarn localghost init --write-scripts
|
|
52
|
+
```
|
|
53
|
+
|
|
54
|
+
This creates `.localghost`:
|
|
55
|
+
|
|
56
|
+
```txt
|
|
57
|
+
# Buh. Friendly names for local services.
|
|
58
|
+
# Format: <host> <port>
|
|
59
|
+
app.localhost 5173
|
|
60
|
+
www.app.localhost 5173
|
|
61
|
+
api.app.localhost 8787
|
|
62
|
+
```
|
|
63
|
+
|
|
64
|
+
Check the machine:
|
|
65
|
+
|
|
66
|
+
```sh
|
|
67
|
+
yarn localghost doctor
|
|
68
|
+
```
|
|
69
|
+
|
|
70
|
+
If Caddy is missing, Localghost prints:
|
|
71
|
+
|
|
72
|
+
```txt
|
|
73
|
+
Caddy: missing
|
|
74
|
+
Run: brew install caddy
|
|
75
|
+
Localghost will not install it for you. No surprise spells.
|
|
76
|
+
```
|
|
77
|
+
|
|
78
|
+
First time on a machine:
|
|
79
|
+
|
|
80
|
+
```sh
|
|
81
|
+
yarn localghost:setup
|
|
82
|
+
```
|
|
83
|
+
|
|
84
|
+
Daily proxy:
|
|
85
|
+
|
|
86
|
+
```sh
|
|
87
|
+
yarn localghost:proxy
|
|
88
|
+
```
|
|
89
|
+
|
|
90
|
+
Prefer `.localhost` names. `.local` is supported, but Localghost warns because `.local` can collide with mDNS/Bonjour.
|
|
91
|
+
|
|
92
|
+
## Config Files
|
|
93
|
+
|
|
94
|
+
By default, Localghost reads `.localghost` from the project root. Repos that need another name can be explicit:
|
|
95
|
+
|
|
96
|
+
```sh
|
|
97
|
+
localghost print --config .localghost.preview
|
|
98
|
+
localghost setup --config .localghost.preview
|
|
99
|
+
```
|
|
100
|
+
|
|
101
|
+
You can pass `--config` more than once. Localghost uses the first file that exists:
|
|
102
|
+
|
|
103
|
+
```sh
|
|
104
|
+
localghost print --config .localghost.private --config .localghost
|
|
105
|
+
```
|
|
106
|
+
|
|
107
|
+
You can also search project-root filenames with a regular expression:
|
|
108
|
+
|
|
109
|
+
```sh
|
|
110
|
+
localghost print --config-pattern '^\.localghost\.(private|preview)$'
|
|
111
|
+
```
|
|
112
|
+
|
|
113
|
+
The Vite plugin accepts the same shape through `fileName`, `configFiles`, or `configPattern`. If you run `localghost init --config .localghost.preview --write-scripts`, generated package scripts include the matching `--config` flag.
|
|
114
|
+
|
|
115
|
+
## Package Scripts
|
|
116
|
+
|
|
117
|
+
`localghost init --write-scripts` adds these scripts when they are missing:
|
|
118
|
+
|
|
119
|
+
```json
|
|
120
|
+
{
|
|
121
|
+
"scripts": {
|
|
122
|
+
"localghost:setup": "localghost setup",
|
|
123
|
+
"localghost:proxy": "localghost dev",
|
|
124
|
+
"localghost:print": "localghost print",
|
|
125
|
+
"localghost:routes": "localghost routes",
|
|
126
|
+
"localghost:status": "localghost status",
|
|
127
|
+
"localghost:teardown": "localghost teardown",
|
|
128
|
+
"localghost:doctor": "localghost doctor",
|
|
129
|
+
"localghost:update": "localghost update"
|
|
130
|
+
}
|
|
131
|
+
}
|
|
132
|
+
```
|
|
133
|
+
|
|
134
|
+
A full app might compose them with its own servers:
|
|
135
|
+
|
|
136
|
+
```json
|
|
137
|
+
{
|
|
138
|
+
"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\""
|
|
142
|
+
}
|
|
143
|
+
}
|
|
144
|
+
```
|
|
145
|
+
|
|
146
|
+
## Vite
|
|
147
|
+
|
|
148
|
+
```ts
|
|
149
|
+
import { defineConfig } from "vite";
|
|
150
|
+
import { localGhostPlugin } from "@hamedb89/localghost/vite";
|
|
151
|
+
|
|
152
|
+
export default defineConfig({
|
|
153
|
+
plugins: [
|
|
154
|
+
localGhostPlugin({
|
|
155
|
+
port: 5173,
|
|
156
|
+
https: true,
|
|
157
|
+
configFiles: [".localghost.private", ".localghost"]
|
|
158
|
+
})
|
|
159
|
+
]
|
|
160
|
+
});
|
|
161
|
+
```
|
|
162
|
+
|
|
163
|
+
The plugin generates an explicit `server.allowedHosts` list from the selected config file; it does not set `allowedHosts: true`.
|
|
164
|
+
|
|
165
|
+
When Vite starts, Localghost prints the browser-facing URLs:
|
|
166
|
+
|
|
167
|
+
```txt
|
|
168
|
+
localghost
|
|
169
|
+
open: https://app.localhost/
|
|
170
|
+
also: https://www.app.localhost/
|
|
171
|
+
target: http://127.0.0.1:5173/
|
|
172
|
+
proxy: Caddy local HTTPS
|
|
173
|
+
```
|
|
174
|
+
|
|
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.
|
|
176
|
+
|
|
177
|
+
Set `log: false` if you want to keep Vite's default terminal output only.
|
|
178
|
+
|
|
179
|
+
## CLI
|
|
180
|
+
|
|
181
|
+
```sh
|
|
182
|
+
localghost init
|
|
183
|
+
localghost init --write-scripts
|
|
184
|
+
localghost doctor
|
|
185
|
+
localghost setup
|
|
186
|
+
localghost setup --project app
|
|
187
|
+
localghost setup --config .localghost.preview
|
|
188
|
+
localghost status
|
|
189
|
+
localghost teardown
|
|
190
|
+
localghost teardown --remove-caddyfile
|
|
191
|
+
localghost update
|
|
192
|
+
localghost --no-update-check doctor
|
|
193
|
+
localghost dev --config-pattern '^\.localghost\.'
|
|
194
|
+
localghost print
|
|
195
|
+
```
|
|
196
|
+
|
|
197
|
+
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
|
+
|
|
199
|
+
`setup` writes only a managed block in the system hosts file:
|
|
200
|
+
|
|
201
|
+
```txt
|
|
202
|
+
# localghost:start app
|
|
203
|
+
127.0.0.1 app.localhost
|
|
204
|
+
# localghost:end app
|
|
205
|
+
```
|
|
206
|
+
|
|
207
|
+
Localghost does not rewrite the whole hosts file. It replaces only its own managed block for the selected project.
|
|
208
|
+
|
|
209
|
+
## Teardown And State
|
|
210
|
+
|
|
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.
|
|
212
|
+
|
|
213
|
+
```sh
|
|
214
|
+
localghost status
|
|
215
|
+
localghost status --json
|
|
216
|
+
```
|
|
217
|
+
|
|
218
|
+
When a project no longer needs Localghost, teardown removes only the managed hosts block for the selected project:
|
|
219
|
+
|
|
220
|
+
```sh
|
|
221
|
+
localghost teardown
|
|
222
|
+
```
|
|
223
|
+
|
|
224
|
+
The generated Caddyfile is left in place by default. Remove it explicitly when you want a fuller cleanup:
|
|
225
|
+
|
|
226
|
+
```sh
|
|
227
|
+
localghost teardown --remove-caddyfile
|
|
228
|
+
```
|
|
229
|
+
|
|
230
|
+
Localghost still uses a short-lived OS temp file while copying `/etc/hosts` with `sudo`, but that temp file is not the source of truth.
|
|
231
|
+
|
|
232
|
+
## API
|
|
233
|
+
|
|
234
|
+
```ts
|
|
235
|
+
import {
|
|
236
|
+
getConfigFileCandidates,
|
|
237
|
+
initLocalghost,
|
|
238
|
+
readDevHosts,
|
|
239
|
+
readLocalghostState,
|
|
240
|
+
removeSystemHosts,
|
|
241
|
+
renderCaddyfile,
|
|
242
|
+
renderHostsBlock,
|
|
243
|
+
runDoctor,
|
|
244
|
+
updateSystemHosts
|
|
245
|
+
} from "@hamedb89/localghost";
|
|
246
|
+
|
|
247
|
+
readDevHosts({ configFiles: [".localghost.private", ".localghost"] });
|
|
248
|
+
readDevHosts({ configPattern: /^\.localghost\.(private|preview)$/ });
|
|
249
|
+
```
|
|
250
|
+
|
|
251
|
+
Vite helper:
|
|
252
|
+
|
|
253
|
+
```ts
|
|
254
|
+
import { localGhostPlugin } from "@hamedb89/localghost/vite";
|
|
255
|
+
```
|
|
256
|
+
|
|
257
|
+
`localHostsPlugin` is also exported as a compatibility alias.
|
|
258
|
+
|
|
259
|
+
## More Docs
|
|
260
|
+
|
|
261
|
+
Localghost copy can be mysterious, goofy, magical, funny, and a little absurd. The product behavior should stay boring in the best way: explicit commands, exact paths, clear errors, and no hidden installs.
|
|
262
|
+
|
|
263
|
+
- [Website](https://hamedb89.github.io/localghost/)
|
|
264
|
+
- [Brand guidelines](./docs/brand.md)
|
|
265
|
+
- [Job-to-be-done flows](./docs/flows.md)
|
|
266
|
+
- [CLI reference](./docs/localghost.1.md)
|
|
267
|
+
|
|
268
|
+
## Assets
|
|
269
|
+
|
|
270
|
+
<p align="center">
|
|
271
|
+
<img src="./assets/localghost-mascot.png" alt="Localghost mascot" width="180">
|
|
272
|
+
<br>
|
|
273
|
+
<img src="./assets/localghost-wordmark.png" alt="Localghost wordmark" width="420">
|
|
274
|
+
</p>
|
|
275
|
+
|
|
276
|
+
## License
|
|
277
|
+
|
|
278
|
+
MIT
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
package/dist/cli.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
#!/usr/bin/env node
|