Skip to content

Commit f9f3ff8

Browse files
committed
Add public GET /api/domain/:name endpoint for nginx domain mapping
1 parent 4ef4589 commit f9f3ff8

3 files changed

Lines changed: 23 additions & 2 deletions

File tree

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "openworkers-api",
3-
"version": "1.8.0",
3+
"version": "1.8.1",
44
"license": "MIT",
55
"type": "module",
66
"repository": {

src/hooks.server.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import { json, type Handle } from '@sveltejs/kit';
22
import { authenticate } from '$lib/server/auth';
33

44
/** Route prefixes that don't require authentication */
5-
const PUBLIC_PREFIXES = ['/api/health'];
5+
const PUBLIC_PREFIXES = ['/api/health', '/api/domain/'];
66

77
/** Routes that don't require authentication */
88
const PUBLIC_ROUTES = new Set([
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
import { json } from '@sveltejs/kit';
2+
import type { RequestHandler } from './$types';
3+
import { domainsService } from '$lib/services/domains';
4+
5+
// GET /api/domain/:name - Public endpoint for nginx domain → worker mapping
6+
export const GET: RequestHandler = async ({ params }) => {
7+
const domain = await domainsService.findByName(params.name);
8+
9+
if (!domain) {
10+
return json({ error: 'Domain not found' }, { status: 404 });
11+
}
12+
13+
return json(
14+
{
15+
workerId: domain.workerId
16+
},
17+
{
18+
headers: { 'Worker-Id': domain.workerId }
19+
}
20+
);
21+
};

0 commit comments

Comments
 (0)