Add a project
A project is a directory, on this machine or on a server, that runs an HTTP service. Nearhost reads the project’s files to work out its ports, then serves it at an alias, <name>.test unless you choose another. The service can be anything that listens on a port.
From the interface
Section titled “From the interface”Press n. A box titled “Add project” opens over the screen. Its steps are counted at the top, and steps that have nothing to ask are skipped. esc goes back a step.
- Server. Pick
localfor this machine, or a server you have added. The selected server, or the selected project’s, is chosen already. New server… adds one on the way. See Add a server. - Path. The project’s directory. On
localit starts as the folder you rannearhostin, and on a server as~/. See Typing a path. - Presets. Nearhost reads ports from
.envby itself. While no preset registry is trusted, it asks once whether to trust the official presets, which add Compose files, Vite and Laravel Sail. Choose Yes, No, or Don’t ask again. With a registry trusted, it lists the presets that suit this project, ticked.spaceunticks one, andenterenables the rest. See Presets and registries. - Routes. The ports found, with a role, what each opens on this machine and a label. Ticked ports are served. The project’s web port opens
https://<alias>, and any otherwebport opens the names it is given. Aloopbackport openslocalhost:<port>, and anignoreport opens nothing. See Routes and roles for what each does. The line under the table says what the selected port’s role does.spaceticks or unticks a port, and←or→changes its role. Changing one port’s role leaves the others as they are. At least one port must beweb, and only onewebport can go without names of its own;entersays so if two do. One port is the project’s web port. To serve another port as well, make itweband give it names of its own withh. If no ports were found, give the web port yourself. The opens column and the line under the table need Nearhost 0.8.0 or later. - Name. The project’s name and its alias. The name is what Nearhost calls the project: in the sidebar, the log and
nearhost up <name>. The alias is the address your browser opens, shown afterhttps://. It follows the name until you change it, unless it comes from the project’s.nearhostrc.tabmoves between them. Names and aliases must be unique. The alias is the project’s main name and can be any lowercase domain name, such aslocal.myapp.com, but not a wildcard,localhostor an IP address. A real domain asks for approval, which typing it here gives. One that comes from the project’s.nearhostrcis asked about on the last step. The hints under the name and alias need Nearhost 0.8.0 or later. - Confirm. The server, path, address and routes, with any advice. It also lists anything that needs approval, such as a host or option from the project’s
.nearhostrc, andenterapproves it as it adds the project.
The project is selected and starts at once. If its alias is not in /etc/hosts yet, Nearhost asks for your password to add it. See First run.
Typing a path
Section titled “Typing a path”Nearhost suggests directories as you type, on this machine and on servers alike. It reads each folder in the background, so typing never waits.
path ~/code/bl▏og/ blog blobThe rest of the suggested name appears faint after the cursor. When several directories match, they are listed under the field.
| Key | Action |
|---|---|
tab, → |
Accept the suggestion. |
↑, ↓ |
Choose between the matches. |
enter |
Use the path exactly as typed, without the suggestion. |
ctrl+r |
Reconnect to the server, if the connection has dropped. |
tab with nothing suggested lists the folder again, which picks up a directory made since. Hidden directories are suggested once you type the ..
From the command line
Section titled “From the command line”nearhost add takes a path and discovers its routes the same way. Run without a terminal, as in a script, it prints:
$ nearhost add --server mini '~/code/myapp' --web 8080No preset registries are trusted. To use the official presets: nearhost preset registry add nearhost/presets
Routes found for myapp (mini:/home/dev/code/myapp): PORT ROLE LABEL 3307 ignore forward-db (FORWARD_DB_PORT) 5174 ignore vite (VITE_PORT) 8080 web app (APP_PORT)
Added myapp on mini at https://myapp.testStart it with `nearhost up`.With no registry trusted, only the .env port variables are found, and every port but the web one is ignore. Here the Vite port should reach the browser as localhost:5174, so change it to loopback afterwards: select the project, press tab, choose the route and press space. The Vite and Sail presets do that for you.
At a terminal it asks what the interface asks: whether to trust the official presets, which suggested presets to enable, and which port is the web app when that is not clear. It also offers to add a server it does not know, and asks you to approve any real domain, wildcard, localhost or Docker access that the project’s .nearhostrc or presets ask for. Without a terminal it takes the defaults, and stops if it cannot tell which port is web or if something needs approval. See Approval.
| Flag | Effect |
|---|---|
--server <name> |
The server the path is on. The default is local. |
--name <name> |
The project name. The default is the directory’s name. |
--alias <alias> |
The main name. The default is <name>.test. Any lowercase domain name works, but not a wildcard, localhost or an IP address. Typing it approves it. |
--web <port> |
The port to serve at the alias. |
--host <host> |
Add this host to the primary web route. Repeat for more. Typing it approves it. |
--preset <name> |
Enable this preset without asking. Repeat for more. |
--no-presets |
Use no presets and suggest none. |
--disabled |
Add it disabled: nearhost up starts it only when named. |
A directory whose name has letters or digits outside ASCII, such as café, needs --name with only a-z, 0-9 and -, or --alias, or an alias in its .nearhostrc. From Nearhost 0.8.0, nearhost add stops and says so.
A ~ in the path means the server’s home directory, even when your shell has already turned it into this machine’s.
Route roles
Section titled “Route roles”| Role | What happens |
|---|---|
web |
Served through the proxy. The first is served at https://<alias>, and each later one at its own hosts. |
loopback |
Raw forward to the same port on your laptop’s 127.0.0.1 and [::1]. Skipped for local projects. |
ignore |
Listed, not forwarded. |
Discovery proposes the roles, and you can change them at any time. See Routes and roles.
A project can have several web routes, each served at hosts of its own. In the form, choose a web route on the routes step and press h to type its hosts. On the command line, --host adds a host to the primary web route. See Multi-host projects.
Advisories are shown, never applied. See Advisories. Nothing on the remote machine is edited.
What gets written
Section titled “What gets written”Every project lives in ~/.config/nearhost/config.yaml. You can edit it by hand too.
projects: - name: myapp server: mini path: /home/dev/code/myapp alias: myapp.test enabled: true routes: - { port: 3307, role: ignore, label: 'forward-db (FORWARD_DB_PORT)' } - { port: 5174, role: loopback, label: 'vite (VITE_PORT)' } - { port: 8080, role: web, label: 'app (APP_PORT)' }See config.yaml for every key.