This repository has been archived by the owner on Sep 16, 2024. It is now read-only.
-
-
Notifications
You must be signed in to change notification settings - Fork 74
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* feat: API versioning * feat: Add versioning logic to root level * Add type; fix todo * Disable token refresh on dev * Make the api versioning backward compatible; keep v1 route active
- Loading branch information
Showing
16 changed files
with
96 additions
and
37 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
import { Request, Response, NextFunction } from 'express'; | ||
|
||
type API_VERSIONS = 'v1' | 'v2' | 'latest'; | ||
|
||
const DEFAULT_API_VERSION: API_VERSIONS = 'v1'; | ||
|
||
declare global { | ||
namespace Express { | ||
interface Request { | ||
version: API_VERSIONS; | ||
} | ||
} | ||
} | ||
|
||
const versionMiddleware = () => async (req: Request, _res: Response, next: () => any) => { | ||
const version = (req.headers['x-api-version'] as API_VERSIONS) || DEFAULT_API_VERSION; | ||
req.version = version; | ||
next(); | ||
}; | ||
|
||
type VersionMap = { | ||
[k in API_VERSIONS]?: any; | ||
}; | ||
|
||
export const manageRouterVersioning = (versionMap: VersionMap) => { | ||
return (req: Request, res: Response, next: NextFunction) => { | ||
const { version } = req; | ||
const fn = versionMap[version] || versionMap[DEFAULT_API_VERSION]; // call the v1 function as default | ||
fn.call(this, req, res, next); | ||
}; | ||
}; | ||
|
||
export default versionMiddleware; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
4 changes: 2 additions & 2 deletions
4
packages/backend/routes/connection/index.ts → ...ges/backend/routes/v1/connection/index.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
8 changes: 4 additions & 4 deletions
8
packages/backend/routes/crm/auth.ts → packages/backend/routes/v1/crm/auth.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
4 changes: 2 additions & 2 deletions
4
packages/backend/routes/crm/company.ts → packages/backend/routes/v1/crm/company.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
4 changes: 2 additions & 2 deletions
4
packages/backend/routes/crm/contact.ts → packages/backend/routes/v1/crm/contact.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
4 changes: 2 additions & 2 deletions
4
packages/backend/routes/crm/deal.ts → packages/backend/routes/v1/crm/deal.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
4 changes: 2 additions & 2 deletions
4
packages/backend/routes/crm/event.ts → packages/backend/routes/v1/crm/event.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
4 changes: 2 additions & 2 deletions
4
packages/backend/routes/crm/lead.ts → packages/backend/routes/v1/crm/lead.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
4 changes: 2 additions & 2 deletions
4
packages/backend/routes/crm/note.ts → packages/backend/routes/v1/crm/note.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
4 changes: 2 additions & 2 deletions
4
packages/backend/routes/crm/proxy.ts → packages/backend/routes/v1/crm/proxy.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
4 changes: 2 additions & 2 deletions
4
packages/backend/routes/crm/task.ts → packages/backend/routes/v1/crm/task.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
4 changes: 2 additions & 2 deletions
4
packages/backend/routes/crm/user.ts → packages/backend/routes/v1/crm/user.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
packages/backend/routes/metadata.ts → packages/backend/routes/v1/metadata.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
7b4b2dc
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Successfully deployed to the following URLs:
revert-react – ./packages/react
revert-react.vercel.app
revert-react-git-main-revertdev.vercel.app
revert-react-revertdev.vercel.app
7b4b2dc
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Successfully deployed to the following URLs:
revert-client – ./
revert-client-git-main-revertdev.vercel.app
revert-client-revertdev.vercel.app
revert-client.vercel.app
app.revert.dev