feat: routing forms for api v2 (#18885)
* init router endpoint for v2 * fixup fixup * resolve merge conflicts * update libraries * update router controller * make router endpoint public * chore: refactor router endpoint and add team/org id * cleanup * chore: Only import Sentry when needed (#18882) * perf: prerender routes in main navigation (#18883) * chore: migrate /apps/categories pages (#18871) * migrate apps/categories pages * remove pages dir * chore: app router - /payment pages (#18152) * remove Head from payment page comp * remove route from pages router * move out of future folder * add to config.matcher * remove unneeded code * update middleware * fix * fix * perf: replace `getServerSessionForAppDir` usages with our original `getServerSession` function (#18897) * chore: migrate /apps/installation pages (#18870) * migrate apps/installation pages * fix test * chore: migrate `/auth/logout` (#18901) * migrate /auth/verify-email page * update middleware * migrate /auth/logout page * expose router endpoint * small refactor pageprops not necessary * sentry is already tracking performance * reuse logic * fixup! reuse logic * fixup! fixup! reuse logic * fixup! fixup! fixup! reuse logic --------- Co-authored-by: Morgan Vernay <[email protected]> Co-authored-by: Alex van Andel <[email protected]> Co-authored-by: Benny Joo <[email protected]> Co-authored-by: Morgan <[email protected]>
This commit is contained in:
9 files changed
+271
-197
No files matched your search
@@ -29,7 +29,7 @@
|
||||
"@axiomhq/winston": "^1.2.0",
|
||||
"@calcom/platform-constants": "*",
|
||||
"@calcom/platform-enums": "*",
|
||||
"@calcom/platform-libraries": "npm:@calcom/[email protected]1",
|
||||
"@calcom/platform-libraries": "npm:@calcom/[email protected]2",
|
||||
"@calcom/platform-libraries-0.0.2": "npm:@calcom/[email protected]",
|
||||
"@calcom/platform-types": "*",
|
||||
"@calcom/platform-utils": "*",
|
||||
|
||||
@@ -4,6 +4,7 @@ import { BillingModule } from "@/modules/billing/billing.module";
|
||||
import { ConferencingModule } from "@/modules/conferencing/conferencing.module";
|
||||
import { DestinationCalendarsModule } from "@/modules/destination-calendars/destination-calendars.module";
|
||||
import { OAuthClientModule } from "@/modules/oauth-clients/oauth-client.module";
|
||||
import { RouterModule } from "@/modules/router/router.module";
|
||||
import { StripeModule } from "@/modules/stripe/stripe.module";
|
||||
import { TimezoneModule } from "@/modules/timezones/timezones.module";
|
||||
import type { MiddlewareConsumer, NestModule } from "@nestjs/common";
|
||||
@@ -24,6 +25,7 @@ import { WebhooksModule } from "./webhooks/webhooks.module";
|
||||
AtomsModule,
|
||||
StripeModule,
|
||||
ConferencingModule,
|
||||
RouterModule,
|
||||
],
|
||||
})
|
||||
export class EndpointsModule implements NestModule {
|
||||
|
||||
@@ -0,0 +1,39 @@
|
||||
import { API_VERSIONS_VALUES } from "@/lib/api-versions";
|
||||
import { Controller, Get, Req, NotFoundException, Res, Query, Param } from "@nestjs/common";
|
||||
import { ApiTags as DocsTags, ApiExcludeController as DocsExcludeController } from "@nestjs/swagger";
|
||||
import { Request, Response } from "express";
|
||||
|
||||
import { getRoutedUrl } from "@calcom/platform-libraries";
|
||||
import { ApiResponse } from "@calcom/platform-types";
|
||||
|
||||
@Controller({
|
||||
path: "/v2/router",
|
||||
version: API_VERSIONS_VALUES,
|
||||
})
|
||||
@DocsTags("Router controller")
|
||||
@DocsExcludeController(true)
|
||||
export class RouterController {
|
||||
@Get("/forms/:formId")
|
||||
async getRoutingFormResponse(
|
||||
@Req() request: Request,
|
||||
@Res() res: Response,
|
||||
@Param("formId") formId: string,
|
||||
@Query() query: Record<string, string>
|
||||
): Promise<void | ApiResponse<unknown>> {
|
||||
const routedUrlData = await getRoutedUrl({ req: request, query: { ...query, form: formId } });
|
||||
|
||||
if (routedUrlData?.notFound) {
|
||||
throw new NotFoundException("Route not found. Please check the provided form parameter.");
|
||||
}
|
||||
|
||||
if (routedUrlData?.redirect?.destination) {
|
||||
return res.redirect(307, routedUrlData.redirect.destination);
|
||||
}
|
||||
|
||||
if (routedUrlData?.props) {
|
||||
return { status: "success", data: routedUrlData.props };
|
||||
}
|
||||
|
||||
return { status: "success", data: "route nor custom message found" };
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
import { PrismaModule } from "@/modules/prisma/prisma.module";
|
||||
import { RouterController } from "@/modules/router/controllers/router.controller";
|
||||
import { Module } from "@nestjs/common";
|
||||
|
||||
@Module({
|
||||
imports: [PrismaModule],
|
||||
providers: [],
|
||||
exports: [],
|
||||
controllers: [RouterController],
|
||||
})
|
||||
export class RouterModule {}
|
||||
Reference in new issue
Block a user