Files
usenet-indexer/start/routes.ts
T
Daan MeijerandClaude Opus 5.5 48f4e982f9
Test and deploy / test (push) Successful in 49s
Test and deploy / deploy (push) Successful in 1m16s
Rebuild: the edge workers' API in its own service
The node API (leases, hour-long streams, batches of up to 256 MB JSON
parsed in-process) shared the web process with the catalog API, Newznab
and the web interface; voyager 1 had to make the same split on
2026-10-06. HTTP_ROUTES picks a process's routes (node, public, all by
default): compose service node-api (same image, port 3335 on the compose
network) serves the workers, web the rest. The workers' COORDINATOR_URL
points at node-api; deploy.sh stops edge before recreating node-api.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-11 19:49:56 +02:00

79 lines
2.8 KiB
TypeScript
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
/*
|--------------------------------------------------------------------------
| Routes file
|--------------------------------------------------------------------------
|
| The routes file is used for defining the HTTP routes.
|
*/
import { middleware } from '#start/kernel'
import router from '@adonisjs/core/services/router'
import { controllers } from '#generated/controllers'
import env from '#start/env'
/**
* Which routes this process serves (HTTP_ROUTES): `node`, the edge workers'
* API only (its own service: hour-long streams and batches of up to 256 MB
* parsed in-process don't hold up the web interface; LOG.md 2026-10-11 (3));
* `public`, everything else; `all` (the default, for development and tests).
*/
const routes = env.get('HTTP_ROUTES', 'all')
const publicRoutes = routes !== 'node'
const nodeRoutes = routes !== 'public'
router.get('/health', () => ({ ok: true, routes }))
if (publicRoutes) {
// The web interface is public/index.html (static middleware).
// Newznab API for Prowlarr, Sonarr, Radarr (from voyager 1).
router.get('/api', [controllers.Newznab, 'handle'])
}
router
.group(() => {
if (publicRoutes) {
router
.group(() => {
router.post('signup', [controllers.NewAccount, 'store'])
router.post('login', [controllers.AccessTokens, 'store'])
})
.prefix('auth')
.as('auth')
router
.group(() => {
router.get('profile', [controllers.Profile, 'show'])
router.post('logout', [controllers.AccessTokens, 'destroy'])
})
.prefix('account')
.as('profile')
.use(middleware.auth())
// The catalog (REBUILD.md, part 9): open, as voyager 1's (the web interface uses it); Newznab has its key.
router.get('releases', [controllers.Releases, 'index'])
router.get('releases/:id', [controllers.Releases, 'show']).where('id', router.matchers.number())
router.get('releases/:id/nzb', [controllers.Releases, 'nzb']).where('id', router.matchers.number())
router.get('stats', [controllers.Releases, 'stats'])
}
if (nodeRoutes) {
// Edge workers (REBUILD.md, parts 1–2).
router
.group(() => {
router.post('lease', [controllers.Node, 'lease'])
router.get('ranges/:id/stream', [controllers.Node, 'stream'])
router.post('ranges/:id/batches', [controllers.Node, 'batch'])
router.post('ranges/:id/heartbeat', [controllers.Node, 'heartbeat'])
router.post('ranges/:id/finish', [controllers.Node, 'finish'])
router.post('ranges/:id/release', [controllers.Node, 'release'])
router.post('ranges/:id/corrupt', [controllers.Node, 'corrupt'])
})
.prefix('node')
.as('node')
.use(middleware.auth({ guards: ['node'] }))
}
})
.prefix('/api/v1')