Skip to content

Commit

Permalink
fix: remove prefix /api from apiv2 (#14559)
Browse files Browse the repository at this point in the history
  • Loading branch information
ThyMinimalDev committed Apr 12, 2024
1 parent 7ad6652 commit 161dcbd
Show file tree
Hide file tree
Showing 5 changed files with 51 additions and 38 deletions.
5 changes: 5 additions & 0 deletions apps/api/v2/src/app.module.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
import { AppLoggerMiddleware } from "@/app.logger.middleware";
import { RewriterMiddleware } from "@/app.rewrites.middleware";
import appConfig from "@/config/app";
import { AuthModule } from "@/modules/auth/auth.module";
import { EndpointsModule } from "@/modules/endpoints.module";
import { JwtModule } from "@/modules/jwt/jwt.module";
import { PrismaModule } from "@/modules/prisma/prisma.module";
import { MiddlewareConsumer, Module, NestModule } from "@nestjs/common";
import { ConfigModule } from "@nestjs/config";
import { RouterModule } from "@nestjs/core";

import { AppController } from "./app.controller";

Expand Down Expand Up @@ -34,11 +36,14 @@ import { AppController } from "./app.controller";
EndpointsModule,
AuthModule,
JwtModule,
//register prefix for all routes in EndpointsModule
RouterModule.register([{ path: "/v2", module: EndpointsModule }]),
],
controllers: [AppController],
})
export class AppModule implements NestModule {
configure(consumer: MiddlewareConsumer): void {
consumer.apply(AppLoggerMiddleware).forRoutes("*");
consumer.apply(RewriterMiddleware).forRoutes("/");
}
}
12 changes: 12 additions & 0 deletions apps/api/v2/src/app.rewrites.middleware.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import { Injectable, NestMiddleware } from "@nestjs/common";
import { Request, Response } from "express";

@Injectable()
export class RewriterMiddleware implements NestMiddleware {
use(req: Request, res: Response, next: () => void) {
if (req.url.startsWith("/api/v2")) {
req.url = req.url.replace("/api/v2", "/v2");
}
next();
}
}
4 changes: 0 additions & 4 deletions apps/api/v2/src/app.ts
Original file line number Diff line number Diff line change
Expand Up @@ -60,10 +60,6 @@ export const bootstrap = (app: NestExpressApplication): NestExpressApplication =
app.useGlobalFilters(new HttpExceptionFilter());
app.useGlobalFilters(new TRPCExceptionFilter());

app.setGlobalPrefix("api", {
exclude: [{ path: "health", method: RequestMethod.GET }],
});

app.use(cookieParser());

return app;
Expand Down
2 changes: 1 addition & 1 deletion apps/api/v2/src/config/app.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ const loadConfig = (): AppConfig => {
process.env.API_PORT && getEnv("NODE_ENV", "development") === "development"
? `:${Number(getEnv("API_PORT", "5555"))}`
: ""
}/api/v2`,
}/v2`,
},
db: {
readUrl: getEnv("DATABASE_READ_URL"),
Expand Down
66 changes: 33 additions & 33 deletions apps/api/v2/swagger/documentation.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
]
}
},
"/api/v2/events/public": {
"/v2/events/public": {
"get": {
"operationId": "EventsController_getPublicEvent",
"parameters": [
Expand Down Expand Up @@ -76,7 +76,7 @@
]
}
},
"/api/v2/oauth-clients/{clientId}/users": {
"/v2/oauth-clients/{clientId}/users": {
"get": {
"operationId": "OAuthClientUsersController_getManagedUsers",
"parameters": [
Expand Down Expand Up @@ -144,7 +144,7 @@
]
}
},
"/api/v2/oauth-clients/{clientId}/users/{userId}": {
"/v2/oauth-clients/{clientId}/users/{userId}": {
"get": {
"operationId": "OAuthClientUsersController_getUserById",
"parameters": [
Expand Down Expand Up @@ -264,7 +264,7 @@
]
}
},
"/api/v2/oauth-clients/{clientId}/users/{userId}/force-refresh": {
"/v2/oauth-clients/{clientId}/users/{userId}/force-refresh": {
"post": {
"operationId": "OAuthClientUsersController_forceRefresh",
"parameters": [
Expand Down Expand Up @@ -302,7 +302,7 @@
]
}
},
"/api/v2/oauth-clients": {
"/v2/oauth-clients": {
"post": {
"operationId": "OAuthClientsController_createOAuthClient",
"summary": "",
Expand Down Expand Up @@ -356,7 +356,7 @@
]
}
},
"/api/v2/oauth-clients/{clientId}": {
"/v2/oauth-clients/{clientId}": {
"get": {
"operationId": "OAuthClientsController_getOAuthClientById",
"summary": "",
Expand Down Expand Up @@ -458,7 +458,7 @@
]
}
},
"/api/v2/oauth/{clientId}/authorize": {
"/v2/oauth/{clientId}/authorize": {
"post": {
"operationId": "OAuthFlowController_authorize",
"summary": "Authorize an OAuth client",
Expand Down Expand Up @@ -496,7 +496,7 @@
]
}
},
"/api/v2/oauth/{clientId}/exchange": {
"/v2/oauth/{clientId}/exchange": {
"post": {
"operationId": "OAuthFlowController_exchange",
"summary": "Exchange authorization code for access tokens",
Expand Down Expand Up @@ -549,7 +549,7 @@
]
}
},
"/api/v2/oauth/{clientId}/refresh": {
"/v2/oauth/{clientId}/refresh": {
"post": {
"operationId": "OAuthFlowController_refreshAccessToken",
"parameters": [
Expand Down Expand Up @@ -597,7 +597,7 @@
]
}
},
"/api/v2/event-types": {
"/v2/event-types": {
"post": {
"operationId": "EventTypesController_createEventType",
"parameters": [],
Expand Down Expand Up @@ -647,7 +647,7 @@
]
}
},
"/api/v2/event-types/{eventTypeId}": {
"/v2/event-types/{eventTypeId}": {
"get": {
"operationId": "EventTypesController_getEventType",
"parameters": [
Expand Down Expand Up @@ -743,7 +743,7 @@
]
}
},
"/api/v2/event-types/{username}/public": {
"/v2/event-types/{username}/public": {
"get": {
"operationId": "EventTypesController_getPublicEventTypes",
"parameters": [
Expand Down Expand Up @@ -773,7 +773,7 @@
]
}
},
"/api/v2/ee/gcal/oauth/auth-url": {
"/v2/ee/gcal/oauth/auth-url": {
"get": {
"operationId": "GcalController_redirect",
"parameters": [
Expand Down Expand Up @@ -803,7 +803,7 @@
]
}
},
"/api/v2/ee/gcal/oauth/save": {
"/v2/ee/gcal/oauth/save": {
"get": {
"operationId": "GcalController_save",
"parameters": [
Expand Down Expand Up @@ -841,7 +841,7 @@
]
}
},
"/api/v2/ee/gcal/check": {
"/v2/ee/gcal/check": {
"get": {
"operationId": "GcalController_check",
"parameters": [],
Expand All @@ -862,7 +862,7 @@
]
}
},
"/api/v2/ee/provider/{clientId}": {
"/v2/ee/provider/{clientId}": {
"get": {
"operationId": "CalProviderController_verifyClientId",
"parameters": [
Expand Down Expand Up @@ -892,7 +892,7 @@
]
}
},
"/api/v2/ee/provider/{clientId}/access-token": {
"/v2/ee/provider/{clientId}/access-token": {
"get": {
"operationId": "CalProviderController_verifyAccessToken",
"parameters": [
Expand Down Expand Up @@ -922,7 +922,7 @@
]
}
},
"/api/v2/schedules": {
"/v2/schedules": {
"post": {
"operationId": "SchedulesController_createSchedule",
"parameters": [],
Expand Down Expand Up @@ -972,7 +972,7 @@
]
}
},
"/api/v2/schedules/default": {
"/v2/schedules/default": {
"get": {
"operationId": "SchedulesController_getDefaultSchedule",
"parameters": [],
Expand All @@ -993,7 +993,7 @@
]
}
},
"/api/v2/schedules/{scheduleId}": {
"/v2/schedules/{scheduleId}": {
"get": {
"operationId": "SchedulesController_getSchedule",
"parameters": [
Expand Down Expand Up @@ -1089,7 +1089,7 @@
]
}
},
"/api/v2/ee/me": {
"/v2/ee/me": {
"get": {
"operationId": "MeController_getMe",
"parameters": [],
Expand Down Expand Up @@ -1139,7 +1139,7 @@
]
}
},
"/api/v2/ee/calendars/busy-times": {
"/v2/ee/calendars/busy-times": {
"get": {
"operationId": "CalendarsController_getBusyTimes",
"parameters": [],
Expand All @@ -1160,7 +1160,7 @@
]
}
},
"/api/v2/ee/calendars": {
"/v2/ee/calendars": {
"get": {
"operationId": "CalendarsController_getCalendars",
"parameters": [],
Expand All @@ -1181,7 +1181,7 @@
]
}
},
"/api/v2/ee/bookings": {
"/v2/ee/bookings": {
"get": {
"operationId": "BookingsController_getBookings",
"parameters": [
Expand Down Expand Up @@ -1272,7 +1272,7 @@
]
}
},
"/api/v2/ee/bookings/{bookingUid}": {
"/v2/ee/bookings/{bookingUid}": {
"get": {
"operationId": "BookingsController_getBooking",
"parameters": [
Expand Down Expand Up @@ -1302,7 +1302,7 @@
]
}
},
"/api/v2/ee/bookings/{bookingUid}/reschedule": {
"/v2/ee/bookings/{bookingUid}/reschedule": {
"get": {
"operationId": "BookingsController_getBookingForReschedule",
"parameters": [
Expand Down Expand Up @@ -1332,7 +1332,7 @@
]
}
},
"/api/v2/ee/bookings/{bookingId}/cancel": {
"/v2/ee/bookings/{bookingId}/cancel": {
"post": {
"operationId": "BookingsController_cancelBooking",
"parameters": [
Expand Down Expand Up @@ -1380,7 +1380,7 @@
]
}
},
"/api/v2/ee/bookings/reccuring": {
"/v2/ee/bookings/reccuring": {
"post": {
"operationId": "BookingsController_createReccuringBooking",
"parameters": [
Expand Down Expand Up @@ -1423,7 +1423,7 @@
]
}
},
"/api/v2/ee/bookings/instant": {
"/v2/ee/bookings/instant": {
"post": {
"operationId": "BookingsController_createInstantBooking",
"parameters": [
Expand Down Expand Up @@ -1463,7 +1463,7 @@
]
}
},
"/api/v2/slots/reserve": {
"/v2/slots/reserve": {
"post": {
"operationId": "SlotsController_reserveSlot",
"parameters": [],
Expand Down Expand Up @@ -1494,7 +1494,7 @@
]
}
},
"/api/v2/slots/selected-slot": {
"/v2/slots/selected-slot": {
"delete": {
"operationId": "SlotsController_deleteSelectedSlot",
"parameters": [],
Expand All @@ -1515,7 +1515,7 @@
]
}
},
"/api/v2/slots/available": {
"/v2/slots/available": {
"get": {
"operationId": "SlotsController_getAvailableSlots",
"parameters": [],
Expand All @@ -1536,7 +1536,7 @@
]
}
},
"/api/v2/timezones": {
"/v2/timezones": {
"get": {
"operationId": "TimezonesController_getTimeZones",
"parameters": [],
Expand Down

0 comments on commit 161dcbd

Please sign in to comment.