@elisoncampos/local-router 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/README.md +115 -0
- package/dist/cli.js +1956 -0
- package/package.json +50 -0
package/README.md
ADDED
|
@@ -0,0 +1,115 @@
|
|
|
1
|
+
# local-router
|
|
2
|
+
|
|
3
|
+
`local-router` exposes dev servers behind stable hostnames, including real domains overridden locally with both HTTP and HTTPS.
|
|
4
|
+
|
|
5
|
+
It is inspired by [portless](https://github.com/vercel-labs/portless), but changes the default behavior to support:
|
|
6
|
+
|
|
7
|
+
- `https://<name>.localhost`
|
|
8
|
+
- `https://app.example.com`
|
|
9
|
+
- `https://api.example.com`
|
|
10
|
+
- the same hosts over plain HTTP
|
|
11
|
+
|
|
12
|
+
## Install
|
|
13
|
+
|
|
14
|
+
```bash
|
|
15
|
+
npm i -g @elisoncampos/local-router
|
|
16
|
+
```
|
|
17
|
+
|
|
18
|
+
Or run it without installing globally:
|
|
19
|
+
|
|
20
|
+
```bash
|
|
21
|
+
npx @elisoncampos/local-router run next dev
|
|
22
|
+
```
|
|
23
|
+
|
|
24
|
+
## Usage
|
|
25
|
+
|
|
26
|
+
Inside a project directory:
|
|
27
|
+
|
|
28
|
+
```bash
|
|
29
|
+
local-router run next dev
|
|
30
|
+
```
|
|
31
|
+
|
|
32
|
+
This infers the project name and exposes:
|
|
33
|
+
|
|
34
|
+
```text
|
|
35
|
+
http://myapp.localhost
|
|
36
|
+
https://myapp.localhost
|
|
37
|
+
```
|
|
38
|
+
|
|
39
|
+
Add a real domain override:
|
|
40
|
+
|
|
41
|
+
```bash
|
|
42
|
+
local-router run next dev --domain app.example.com
|
|
43
|
+
```
|
|
44
|
+
|
|
45
|
+
This adds:
|
|
46
|
+
|
|
47
|
+
```text
|
|
48
|
+
http://app.example.com
|
|
49
|
+
https://app.example.com
|
|
50
|
+
```
|
|
51
|
+
|
|
52
|
+
You can repeat `--domain` as many times as needed.
|
|
53
|
+
|
|
54
|
+
## `.local-router`
|
|
55
|
+
|
|
56
|
+
Create a `.local-router` file in the project root using JSON5 syntax:
|
|
57
|
+
|
|
58
|
+
```js
|
|
59
|
+
{
|
|
60
|
+
name: "algo",
|
|
61
|
+
hosts: [
|
|
62
|
+
"app.example.com",
|
|
63
|
+
"api.example.com"
|
|
64
|
+
]
|
|
65
|
+
}
|
|
66
|
+
```
|
|
67
|
+
|
|
68
|
+
Then:
|
|
69
|
+
|
|
70
|
+
```bash
|
|
71
|
+
local-router run next dev
|
|
72
|
+
```
|
|
73
|
+
|
|
74
|
+
Exposes:
|
|
75
|
+
|
|
76
|
+
```text
|
|
77
|
+
http://algo.localhost
|
|
78
|
+
https://algo.localhost
|
|
79
|
+
http://app.example.com
|
|
80
|
+
https://app.example.com
|
|
81
|
+
http://api.example.com
|
|
82
|
+
https://api.example.com
|
|
83
|
+
```
|
|
84
|
+
|
|
85
|
+
## How it works
|
|
86
|
+
|
|
87
|
+
- A shared proxy daemon listens on ports `80` and `443` by default.
|
|
88
|
+
- Your app runs on an ephemeral port like `4624`.
|
|
89
|
+
- `local-router` registers every hostname for that app.
|
|
90
|
+
- The proxy forwards requests by `Host`.
|
|
91
|
+
- For custom domains, `local-router` manages a block in `/etc/hosts`.
|
|
92
|
+
- For HTTPS, `local-router` generates a local CA and per-host certificates.
|
|
93
|
+
|
|
94
|
+
## Important note about sudo
|
|
95
|
+
|
|
96
|
+
Ports `80` and `443` require elevated privileges on macOS/Linux.
|
|
97
|
+
|
|
98
|
+
The CLI will prompt to start the proxy with `sudo` when required.
|
|
99
|
+
|
|
100
|
+
If you only want to test the project on high ports:
|
|
101
|
+
|
|
102
|
+
```bash
|
|
103
|
+
LOCAL_ROUTER_HTTP_PORT=18080 LOCAL_ROUTER_HTTPS_PORT=18443 local-router run next dev
|
|
104
|
+
```
|
|
105
|
+
|
|
106
|
+
## Commands
|
|
107
|
+
|
|
108
|
+
```bash
|
|
109
|
+
local-router run <command...>
|
|
110
|
+
local-router proxy start
|
|
111
|
+
local-router proxy stop
|
|
112
|
+
local-router trust
|
|
113
|
+
local-router hosts sync
|
|
114
|
+
local-router hosts clean
|
|
115
|
+
```
|