Skip to content

Commit 0cd40ab

Browse files
committed
feat(discovery): add discovery endpoint for redirecting to API in NestJS and Next.js adapters
1 parent 5546e93 commit 0cd40ab

File tree

3 files changed

+36
-1
lines changed

3 files changed

+36
-1
lines changed

packages/adapters/nestjs/src/index.ts

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -168,6 +168,16 @@ export class ObjectStackController {
168168
}
169169
}
170170

171+
// --- Discovery Controller ---
172+
173+
@Controller('.well-known')
174+
export class DiscoveryController {
175+
@Get('objectstack')
176+
discover(@Res() res: any) {
177+
return res.redirect('/api');
178+
}
179+
}
180+
171181
// --- Module ---
172182

173183
@Global()
@@ -181,7 +191,7 @@ export class ObjectStackModule {
181191

182192
return {
183193
module: ObjectStackModule,
184-
controllers: [ObjectStackController],
194+
controllers: [ObjectStackController, DiscoveryController],
185195
providers: [kernelProvider, ObjectStackService],
186196
exports: [kernelProvider, ObjectStackService],
187197
};

packages/adapters/nextjs/src/index.ts

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -123,3 +123,16 @@ export function createRouteHandler(options: NextAdapterOptions) {
123123
}
124124
}
125125
}
126+
127+
/**
128+
* Creates a discovery handler for Next.js App Router
129+
* Handles /.well-known/objectstack
130+
*/
131+
export function createDiscoveryHandler(options: NextAdapterOptions) {
132+
return async function discoveryHandler(req: NextRequest) {
133+
const apiPath = options.prefix || '/api';
134+
const url = new URL(req.url);
135+
const targetUrl = new URL(apiPath, url.origin);
136+
return NextResponse.redirect(targetUrl);
137+
}
138+
}

packages/plugins/plugin-msw/src/msw-plugin.ts

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -200,6 +200,18 @@ export class MSWPlugin implements Plugin {
200200
...(this.options.customHandlers || [])
201201
];
202202

203+
// Discovery Endpoint
204+
this.handlers.push(
205+
http.get('*/.well-known/objectstack', () => {
206+
return new HttpResponse(null, {
207+
status: 302,
208+
headers: {
209+
Location: baseUrl
210+
}
211+
})
212+
})
213+
);
214+
203215
if (this.dispatcher) {
204216
const dispatcher = this.dispatcher;
205217

0 commit comments

Comments
 (0)