mk-https 1.0.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 +256 -0
- package/dist/index.js +1109 -0
- package/package.json +67 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Sourav Shrestha
|
|
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,256 @@
|
|
|
1
|
+
# mk-https
|
|
2
|
+
|
|
3
|
+
Zero to `https://myapp.local` in one command. Wraps [mkcert](https://github.com/FiloSottile/mkcert) to generate trusted local certificates, manage `/etc/hosts` entries, and print framework config snippets for Next.js, Vite, Express, and Angular.
|
|
4
|
+
|
|
5
|
+
---
|
|
6
|
+
|
|
7
|
+
## Requirements
|
|
8
|
+
|
|
9
|
+
- **Node.js** 20 LTS or later
|
|
10
|
+
- **mkcert** (installed automatically if missing via `brew`, `snap`, `apt-get`, `choco`, or `scoop`)
|
|
11
|
+
- macOS, Linux, or Windows
|
|
12
|
+
|
|
13
|
+
---
|
|
14
|
+
|
|
15
|
+
## Installation
|
|
16
|
+
|
|
17
|
+
```bash
|
|
18
|
+
npm install -g mk-https
|
|
19
|
+
# or
|
|
20
|
+
npx mk-https init
|
|
21
|
+
```
|
|
22
|
+
|
|
23
|
+
---
|
|
24
|
+
|
|
25
|
+
## Commands
|
|
26
|
+
|
|
27
|
+
### `mk-https init`
|
|
28
|
+
|
|
29
|
+
Set up HTTPS for the current project from scratch.
|
|
30
|
+
|
|
31
|
+
- Prompts for domain(s) if no config file exists yet (or pass `--domain` to skip the prompt)
|
|
32
|
+
- Auto-detects your framework (Next.js, Vite, Angular, Express) from config files and `package.json`
|
|
33
|
+
- Installs `mkcert` if it is not already present
|
|
34
|
+
- Installs the local CA if not yet trusted
|
|
35
|
+
- Generates `cert.pem` and `key.pem` into `.mk-https/`
|
|
36
|
+
- Adds entries to `/etc/hosts` (requires elevated privileges — will prompt for `sudo`)
|
|
37
|
+
- Appends `.mk-https/` to `.gitignore`
|
|
38
|
+
- Writes `.mk-https/mk-https.json`
|
|
39
|
+
- Prints a config snippet for your framework
|
|
40
|
+
|
|
41
|
+
```bash
|
|
42
|
+
mk-https init
|
|
43
|
+
|
|
44
|
+
# Non-interactive (for CI/scripts):
|
|
45
|
+
mk-https init --domain myapp.local --domain api.myapp.local
|
|
46
|
+
```
|
|
47
|
+
|
|
48
|
+
### `mk-https add <domain>`
|
|
49
|
+
|
|
50
|
+
Add an additional domain to the existing HTTPS setup.
|
|
51
|
+
|
|
52
|
+
- Validates the domain format (must end in `.local`, `.test`, `.localhost`, or `.internal`)
|
|
53
|
+
- Regenerates the certificate to cover all domains
|
|
54
|
+
- Adds the new entry to `/etc/hosts`
|
|
55
|
+
- Updates `mk-https.json`
|
|
56
|
+
|
|
57
|
+
```bash
|
|
58
|
+
mk-https add api.myapp.local
|
|
59
|
+
```
|
|
60
|
+
|
|
61
|
+
### `mk-https remove <domain>`
|
|
62
|
+
|
|
63
|
+
Remove a domain from the HTTPS setup.
|
|
64
|
+
|
|
65
|
+
- Regenerates the certificate without the removed domain
|
|
66
|
+
- Removes the entry from `/etc/hosts`
|
|
67
|
+
- Updates `mk-https.json`
|
|
68
|
+
|
|
69
|
+
```bash
|
|
70
|
+
mk-https remove api.myapp.local
|
|
71
|
+
```
|
|
72
|
+
|
|
73
|
+
### `mk-https status`
|
|
74
|
+
|
|
75
|
+
Show the current state of the HTTPS setup for this project.
|
|
76
|
+
|
|
77
|
+
- Lists configured domains
|
|
78
|
+
- Reports certificate expiry date (warns if expiring within 30 days)
|
|
79
|
+
- Checks local CA trust
|
|
80
|
+
- Checks `/etc/hosts` entries
|
|
81
|
+
|
|
82
|
+
```bash
|
|
83
|
+
mk-https status
|
|
84
|
+
```
|
|
85
|
+
|
|
86
|
+
### `mk-https renew`
|
|
87
|
+
|
|
88
|
+
Regenerate the certificate for existing domains without touching `/etc/hosts`.
|
|
89
|
+
|
|
90
|
+
```bash
|
|
91
|
+
mk-https renew
|
|
92
|
+
```
|
|
93
|
+
|
|
94
|
+
### `mk-https clean`
|
|
95
|
+
|
|
96
|
+
Remove all mk-https configuration for this project.
|
|
97
|
+
|
|
98
|
+
- Strips the marker block from `/etc/hosts`
|
|
99
|
+
- Deletes the `.mk-https/` directory (certs and config)
|
|
100
|
+
- Strips the marker block from `.gitignore`
|
|
101
|
+
- Does **not** remove `mkcert` or the local CA — those are system-level
|
|
102
|
+
|
|
103
|
+
```bash
|
|
104
|
+
mk-https clean
|
|
105
|
+
```
|
|
106
|
+
|
|
107
|
+
### `mk-https doctor`
|
|
108
|
+
|
|
109
|
+
Run a full environment health check and print a pass/fail summary for each item:
|
|
110
|
+
|
|
111
|
+
```
|
|
112
|
+
✔ mkcert installed
|
|
113
|
+
✔ Local CA trusted (OS cert store)
|
|
114
|
+
✘ Firefox trust (NSS certutil present) — install libnss3-tools for Firefox support
|
|
115
|
+
✔ Cert file exists
|
|
116
|
+
✔ Key file exists
|
|
117
|
+
✔ Cert covers all configured domains
|
|
118
|
+
✔ Cert validity — expires Thu Jan 01 2026 (365 days)
|
|
119
|
+
✔ /etc/hosts entries present
|
|
120
|
+
✔ mk-https.json schema version current
|
|
121
|
+
```
|
|
122
|
+
|
|
123
|
+
```bash
|
|
124
|
+
mk-https doctor
|
|
125
|
+
```
|
|
126
|
+
|
|
127
|
+
---
|
|
128
|
+
|
|
129
|
+
## Framework setup
|
|
130
|
+
|
|
131
|
+
`mk-https init` detects your framework and prints the config snippet you need. You can also run `mk-https doctor` any time to check the full environment.
|
|
132
|
+
|
|
133
|
+
### Next.js (≥ 13.1)
|
|
134
|
+
|
|
135
|
+
```ts
|
|
136
|
+
// next.config.ts
|
|
137
|
+
const nextConfig = {
|
|
138
|
+
experimental: {
|
|
139
|
+
https: {
|
|
140
|
+
key: '.mk-https/key.pem',
|
|
141
|
+
cert: '.mk-https/cert.pem',
|
|
142
|
+
},
|
|
143
|
+
},
|
|
144
|
+
};
|
|
145
|
+
|
|
146
|
+
export default nextConfig;
|
|
147
|
+
```
|
|
148
|
+
|
|
149
|
+
> **Next.js 14+ App Router note:** Local HTTPS dev works with `experimental.https`, but some middleware and edge features may behave differently over HTTPS in development.
|
|
150
|
+
|
|
151
|
+
### Vite
|
|
152
|
+
|
|
153
|
+
```ts
|
|
154
|
+
// vite.config.ts
|
|
155
|
+
import { defineConfig } from 'vite';
|
|
156
|
+
import fs from 'fs';
|
|
157
|
+
|
|
158
|
+
export default defineConfig({
|
|
159
|
+
server: {
|
|
160
|
+
https: {
|
|
161
|
+
key: fs.readFileSync('.mk-https/key.pem'),
|
|
162
|
+
cert: fs.readFileSync('.mk-https/cert.pem'),
|
|
163
|
+
},
|
|
164
|
+
},
|
|
165
|
+
});
|
|
166
|
+
```
|
|
167
|
+
|
|
168
|
+
### Express
|
|
169
|
+
|
|
170
|
+
```js
|
|
171
|
+
import https from 'https';
|
|
172
|
+
import { readFileSync } from 'fs';
|
|
173
|
+
import app from './app.js';
|
|
174
|
+
|
|
175
|
+
const server = https.createServer(
|
|
176
|
+
{
|
|
177
|
+
key: readFileSync('.mk-https/key.pem'),
|
|
178
|
+
cert: readFileSync('.mk-https/cert.pem'),
|
|
179
|
+
},
|
|
180
|
+
app,
|
|
181
|
+
);
|
|
182
|
+
|
|
183
|
+
server.listen(443);
|
|
184
|
+
```
|
|
185
|
+
|
|
186
|
+
### Angular
|
|
187
|
+
|
|
188
|
+
```json
|
|
189
|
+
// angular.json — projects.<name>.architect.serve.options
|
|
190
|
+
{
|
|
191
|
+
"ssl": true,
|
|
192
|
+
"sslKey": ".mk-https/key.pem",
|
|
193
|
+
"sslCert": ".mk-https/cert.pem"
|
|
194
|
+
}
|
|
195
|
+
```
|
|
196
|
+
|
|
197
|
+
Or via CLI:
|
|
198
|
+
|
|
199
|
+
```bash
|
|
200
|
+
ng serve --ssl --ssl-key .mk-https/key.pem --ssl-cert .mk-https/cert.pem
|
|
201
|
+
```
|
|
202
|
+
|
|
203
|
+
---
|
|
204
|
+
|
|
205
|
+
## How it works
|
|
206
|
+
|
|
207
|
+
1. **mkcert** creates a local Certificate Authority (CA) and installs it into the OS cert store (and Chrome/Edge on macOS/Windows).
|
|
208
|
+
2. mk-https uses that CA to issue a certificate for your local domain(s) (`.local`, `.test`, `.localhost`, or `.internal`).
|
|
209
|
+
3. Entries are added to `/etc/hosts` so the domain resolves to `127.0.0.1` and `::1` (IPv6).
|
|
210
|
+
4. Your browser trusts the cert because it trusts the local CA.
|
|
211
|
+
|
|
212
|
+
### Firefox
|
|
213
|
+
|
|
214
|
+
Firefox uses its own NSS cert store. `mkcert -install` covers this automatically **if** `certutil` is present. Install it with:
|
|
215
|
+
|
|
216
|
+
- **Linux:** `sudo apt-get install libnss3-tools`
|
|
217
|
+
- **macOS:** `brew install nss`
|
|
218
|
+
|
|
219
|
+
Run `mk-https doctor` to check if `certutil` is available.
|
|
220
|
+
|
|
221
|
+
### Elevation / sudo
|
|
222
|
+
|
|
223
|
+
Writing to `/etc/hosts` requires administrator privileges. When needed, mk-https re-invokes itself with `sudo` (macOS/Linux) or via a UAC-elevated PowerShell process (Windows). You will see a password prompt the first time. On Linux/macOS you can also pre-authorize with `sudo -v`.
|
|
224
|
+
|
|
225
|
+
---
|
|
226
|
+
|
|
227
|
+
## Project config (`.mk-https/mk-https.json`)
|
|
228
|
+
|
|
229
|
+
```json
|
|
230
|
+
{
|
|
231
|
+
"version": "1.0.0",
|
|
232
|
+
"domains": ["myapp.local", "api.myapp.local"],
|
|
233
|
+
"certPath": ".mk-https/cert.pem",
|
|
234
|
+
"keyPath": ".mk-https/key.pem",
|
|
235
|
+
"framework": "nextjs",
|
|
236
|
+
"createdAt": "2024-01-01T00:00:00.000Z",
|
|
237
|
+
"updatedAt": "2024-01-01T00:00:00.000Z"
|
|
238
|
+
}
|
|
239
|
+
```
|
|
240
|
+
|
|
241
|
+
The `.mk-https/` directory is automatically added to `.gitignore` — never commit your local certs.
|
|
242
|
+
|
|
243
|
+
---
|
|
244
|
+
|
|
245
|
+
## Notes
|
|
246
|
+
|
|
247
|
+
- mk-https never runs side effects during `npm install` (no `postinstall` scripts).
|
|
248
|
+
- All paths are resolved relative to the current working directory (`process.cwd()`).
|
|
249
|
+
- Framework config files are **not** modified — only a snippet is printed for you to copy.
|
|
250
|
+
- `mk-https clean` removes project-level HTTPS config but does **not** uninstall `mkcert` or the local CA.
|
|
251
|
+
|
|
252
|
+
---
|
|
253
|
+
|
|
254
|
+
## License
|
|
255
|
+
|
|
256
|
+
MIT
|