Skip to content

Commit f933b5f

Browse files
chore: auto-start Redis and handle port collisions (#581)
1 parent 83137b5 commit f933b5f

8 files changed

Lines changed: 659 additions & 22 deletions

File tree

README.md

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -18,17 +18,18 @@ npm install
1818
# Build all packages
1919
npm run build
2020

21-
# Start Redis (requires Docker)
22-
npm run start:localdb
23-
2421
# Start dev stack with hot reload
2522
npm run dev
2623
```
2724

2825
This starts:
2926
- **Library** build watch (auto-rebuilds on changes)
30-
- **Server** (tsx watch) on http://localhost:8000 with WebSocket relay on ws://localhost:4444
31-
- **Webapp** (Vite HMR) on http://localhost:5173
27+
- **Server** (tsx watch) on a printed local HTTP port with a matching WebSocket relay port
28+
- **Webapp** (Vite HMR) on a printed local dev URL
29+
30+
`npm run dev` also handles local port collisions for the webapp, server, WebSocket relay, and Redis. It reuses an existing local Redis when possible and otherwise starts the local Redis container on a free host port. Docker still needs to be available when no compatible local Redis is already running.
31+
32+
If you need to pin preferred ports, set `APOLLON_WEBAPP_PORT`, `APOLLON_SERVER_PORT`, `APOLLON_WS_PORT`, or `APOLLON_REDIS_PORT` before running `npm run dev`.
3233

3334
No `.env` files needed — defaults match the local setup.
3435

@@ -58,7 +59,7 @@ For complete documentation, setup instructions, and guides, visit:
5859

5960
- **Node.js** (version specified in `.nvmrc`)
6061
- **npm** 7+ (for workspace support)
61-
- **Docker** (for running Redis locally)
62+
- **Docker** (for running Redis locally via `npm run dev` or `npm run start:localdb`)
6263

6364
## Contributing
6465

docker/compose.local.db.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ services:
22
db:
33
image: redis:7-alpine
44
ports:
5-
- "6379:6379"
5+
- "${REDIS_PORT:-6379}:6379"
66
volumes:
77
- dbdata:/data
88

docs/development/scripts.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,8 @@ Here are the commonly used scripts defined in the monorepo:
2222
```bash
2323
npm run dev
2424
```
25-
Starts the library (build watch), server (tsx watch on http://localhost:8000), and webapp (Vite HMR on http://localhost:5173) concurrently.
25+
Starts the library (build watch), server, and webapp concurrently. The command also resolves local port collisions for the webapp, server, WebSocket relay, and Redis, and it starts the local Redis container only when no compatible local Redis instance is already reachable.
26+
You can prefer custom ports by setting `APOLLON_WEBAPP_PORT`, `APOLLON_SERVER_PORT`, `APOLLON_WS_PORT`, or `APOLLON_REDIS_PORT` before starting the stack.
2627

2728
- **Start production build:**
2829
```bash

docs/getting-started/setup.md

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -30,18 +30,12 @@ Follow these steps to set up the Apollon monorepo on your local machine.
3030
npm run build
3131
```
3232

33-
5. **Start Redis** (requires Docker):
34-
35-
```bash
36-
npm run start:localdb
37-
```
38-
39-
6. **Start development with hot reload:**
33+
5. **Start development with hot reload** (requires Docker for Redis):
4034

4135
```bash
4236
npm run dev
4337
```
4438

45-
This starts the library (build watch), server (http://localhost:8000), and webapp (http://localhost:5173) with hot reload.
39+
This starts the library (build watch), server, webapp, and the local Redis dependency used by the server. If the default local ports are already in use, the command selects free ports automatically and prints the chosen URLs in the terminal output.
4640

4741
No `.env` files are needed — all defaults match the local setup. See `standalone/server/.env.example` and `standalone/webapp/.env.example` if you need to override defaults.

package.json

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,16 +14,18 @@
1414
"build:server": "npm run build --workspace=@tumaet/server",
1515
"build:webapp": "npm run build --workspace=@tumaet/webapp",
1616
"build:vscode": "npm run build:all --workspace=apollon-vscode",
17-
"dev": "concurrently -n lib,server,webapp -c yellow,blue,magenta \"npm run dev:lib\" \"npm run dev:server\" \"npm run dev:webapp\"",
17+
"dev": "node scripts/dev.mjs",
1818
"dev:lib": "npm run build:watch --workspace=@tumaet/apollon",
19-
"dev:server": "npm run dev --workspace=@tumaet/server",
19+
"dev:server": "npm run ensure:localdb && npm run dev --workspace=@tumaet/server",
2020
"dev:webapp": "npm run start --workspace=@tumaet/webapp",
2121
"dev:vscode": "npm run watch --workspace=apollon-vscode",
2222
"start": "concurrently \"npm run start:server\" \"npm run start:webapp\"",
2323
"start:server": "npm run start --workspace=@tumaet/server",
2424
"start:webapp": "npm run start --workspace=@tumaet/webapp",
2525
"start:webapp:host": "npm run start:host --workspace=@tumaet/webapp",
2626
"start:localdb": "docker compose -f docker/compose.local.db.yml up -d",
27+
"wait:localdb": "node scripts/wait-for-redis.mjs",
28+
"ensure:localdb": "npm run start:localdb && npm run wait:localdb",
2729
"lint": "concurrently \"npm run lint:lib\" \"npm run lint:server\" \"npm run lint:webapp\"",
2830
"lint:lib": "npm run lint --workspace=@tumaet/apollon",
2931
"lint:server": "npm run lint --workspace=@tumaet/server",

0 commit comments

Comments
 (0)