Move / endpoint to /topics and add version endpoint

- Move GET / to GET /topics for listing topics
- Add new GET / endpoint that returns server version (git commit hash)
- Update build.js to inject git commit hash as RONDEVU_VERSION
- Update API documentation

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
2025-11-08 11:34:54 +01:00
parent b89d281548
commit d4aefb93b0
3 changed files with 62 additions and 10 deletions

48
API.md
View File

@@ -19,6 +19,33 @@ This allows multiple peers from the same application (origin) to discover each o
## GET `/` ## GET `/`
Returns server version information including the git commit hash used to build the server.
### Response
**Content-Type:** `application/json`
**Success (200 OK):**
```json
{
"version": "a1b2c3d"
}
```
**Notes:**
- Returns the git commit hash from build time
- Returns "unknown" if git information is not available
### Example
```bash
curl -X GET http://localhost:3000/
```
---
## GET `/topics`
Lists all topics with the count of available peers for each (paginated). Returns only topics that have unanswered sessions. Lists all topics with the count of available peers for each (paginated). Returns only topics that have unanswered sessions.
### Request ### Request
@@ -70,13 +97,13 @@ Lists all topics with the count of available peers for each (paginated). Returns
**Default pagination (page 1, limit 100):** **Default pagination (page 1, limit 100):**
```bash ```bash
curl -X GET http://localhost:3000/ \ curl -X GET http://localhost:3000/topics \
-H "Origin: https://example.com" -H "Origin: https://example.com"
``` ```
**Custom pagination:** **Custom pagination:**
```bash ```bash
curl -X GET "http://localhost:3000/?page=2&limit=50" \ curl -X GET "http://localhost:3000/topics?page=2&limit=50" \
-H "Origin: https://example.com" -H "Origin: https://example.com"
``` ```
@@ -403,26 +430,29 @@ All endpoints may return the following error responses:
### Peer Discovery and Connection ### Peer Discovery and Connection
1. **Discover active topics:** 1. **Check server version (optional):**
- GET `/` to see all topics and peer counts - GET `/` to see server version information
2. **Discover active topics:**
- GET `/topics` to see all topics and peer counts
- Optional: paginate through results with `?page=2&limit=100` - Optional: paginate through results with `?page=2&limit=100`
2. **Peer A announces availability:** 3. **Peer A announces availability:**
- POST `/:topic/offer` with peer identifier and signaling data - POST `/:topic/offer` with peer identifier and signaling data
- Receives a unique session code - Receives a unique session code
3. **Peer B discovers peers:** 4. **Peer B discovers peers:**
- GET `/:topic/sessions` to list available sessions in a topic - GET `/:topic/sessions` to list available sessions in a topic
- Filters out sessions with their own info to avoid self-connection - Filters out sessions with their own info to avoid self-connection
- Selects a peer to connect to - Selects a peer to connect to
4. **Peer B initiates connection:** 5. **Peer B initiates connection:**
- POST `/answer` with the session code and their signaling data - POST `/answer` with the session code and their signaling data
5. **Both peers exchange signaling information:** 6. **Both peers exchange signaling information:**
- POST `/answer` with additional signaling data as needed - POST `/answer` with additional signaling data as needed
- POST `/poll` to retrieve signaling data from the other peer - POST `/poll` to retrieve signaling data from the other peer
6. **Peer connection established** 7. **Peer connection established**
- Peers use exchanged signaling data to establish direct connection - Peers use exchanged signaling data to establish direct connection
- Session automatically expires after configured timeout - Session automatically expires after configured timeout

View File

@@ -1,5 +1,14 @@
// Build script using esbuild // Build script using esbuild
const esbuild = require('esbuild'); const esbuild = require('esbuild');
const { execSync } = require('child_process');
// Get git commit hash
let version = 'unknown';
try {
version = execSync('git rev-parse --short HEAD', { encoding: 'utf8' }).trim();
} catch (err) {
console.warn('Could not get git commit hash, using "unknown"');
}
esbuild.build({ esbuild.build({
entryPoints: ['src/index.ts'], entryPoints: ['src/index.ts'],
@@ -14,4 +23,7 @@ esbuild.build({
'hono' 'hono'
], ],
sourcemap: true, sourcemap: true,
define: {
'process.env.RONDEVU_VERSION': JSON.stringify(version)
}
}).catch(() => process.exit(1)); }).catch(() => process.exit(1));

View File

@@ -50,10 +50,20 @@ export function createApp(storage: Storage, config: AppConfig) {
/** /**
* GET / * GET /
* Returns server version information
*/
app.get('/', (c) => {
return c.json({
version: process.env.RONDEVU_VERSION || 'unknown'
});
});
/**
* GET /topics
* Lists all topics with their unanswered session counts (paginated) * Lists all topics with their unanswered session counts (paginated)
* Query params: page (default: 1), limit (default: 100, max: 1000) * Query params: page (default: 1), limit (default: 100, max: 1000)
*/ */
app.get('/', async (c) => { app.get('/topics', async (c) => {
try { try {
const origin = getOrigin(c); const origin = getOrigin(c);
const page = parseInt(c.req.query('page') || '1', 10); const page = parseInt(c.req.query('page') || '1', 10);