File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -37,4 +37,8 @@ AXIOM_TOKEN=
3737# INFO: 1
3838# WARN: 2
3939# ERROR: 3
40- LOGGER_BRIDGE_LOG_LEVEL = " 1"
40+ LOGGER_BRIDGE_LOG_LEVEL = " 1"
41+
42+ # 1: Rewrite /api/v2 to /v2
43+ # 0: Don't rewrite
44+ REWRITE_API_V2_PREFIX = " 1"
Original file line number Diff line number Diff line change @@ -32,6 +32,8 @@ export type Environment = {
3232 AXIOM_TOKEN : string ;
3333 STRIPE_TEAM_MONTHLY_PRICE_ID : string ;
3434 IS_TEAM_BILLING_ENABLED : boolean ;
35+ // Used to enable/disable the rewrite of /api/v2 to /v2, active by default.
36+ REWRITE_API_V2_PREFIX : string ;
3537} ;
3638
3739export const getEnv = < K extends keyof Environment > ( key : K , fallback ?: Environment [ K ] ) : Environment [ K ] => {
Original file line number Diff line number Diff line change 1+ import { getEnv } from "@/env" ;
12import { Injectable , NestMiddleware } from "@nestjs/common" ;
23import { Request , Response } from "express" ;
34
45@Injectable ( )
56export class RewriterMiddleware implements NestMiddleware {
67 use ( req : Request , res : Response , next : ( ) => void ) {
7- if ( req . url . startsWith ( "/api/v2" ) ) {
8+ if ( shouldRewriteApiV2Prefix ( ) && req . url . startsWith ( "/api/v2" ) ) {
89 req . url = req . url . replace ( "/api/v2" , "/v2" ) ;
910 }
1011 if ( req . url . startsWith ( "/v2/ee" ) ) {
@@ -16,3 +17,12 @@ export class RewriterMiddleware implements NestMiddleware {
1617 next ( ) ;
1718 }
1819}
20+
21+ const shouldRewriteApiV2Prefix = ( ) => {
22+ try {
23+ // rewrite is active even if REWRITE_API_V2_PREFIX is not set
24+ return getEnv ( "REWRITE_API_V2_PREFIX" , "1" ) === "1" ;
25+ } catch ( error ) {
26+ return true ;
27+ }
28+ } ;
You can’t perform that action at this time.
0 commit comments