Skip to content

Commit

Permalink
feat: add new /api/v1 prefix to all routes
Browse files Browse the repository at this point in the history
  • Loading branch information
kieranroneill committed Mar 18, 2024
1 parent aae01a9 commit a8daf4e
Show file tree
Hide file tree
Showing 7 changed files with 29 additions and 7 deletions.
17 changes: 12 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,9 @@
- [2.2. Setting up environment variables (optional)](#22-setting-up-environment-variables-optional)
- [2.3. Running locally](#23-running-locally)
* [3. Appendix](#-3-appendix)
- [3.1. Useful commands](#31-useful-commands)
- [3.2. Docker Compose service directory](#32-docker-compose-service-directory)
- [3.1. Documentation](#31-documentation)
- [3.2. Useful commands](#32-useful-commands)
- [3.3. Docker Compose service directory](#33-docker-compose-service-directory)
* [4. How To Contribute](#-4-how-to-contribute)
* [5. License](#-5-license)

Expand Down Expand Up @@ -85,13 +86,19 @@ yarn start

> ⚠️ **NOTE:** The `yarn start` command will run/re-run the setup script, but will not overwrite the file `.env` that was created and edited in section [1.2.](#22-setting-up-environment-variables-optional)
2. Navigate to [http://localhost:3000/versions](http://localhost:3000/versions) to make sure everything is runnning.
2. Navigate to [http://localhost:3000/api/v1/versions](http://localhost:3000/api/v1/versions) to make sure everything is running.

<sup>[Back to top ^][table-of-contents]</sup>

## 📑 3. Appendix

### 3.1. Useful commands
### 3.1. Documentation

The API comes with some OpenAPI documentation. This can be accessed at [http://localhost:3000/api](http://localhost:3000/api).

This documentation outlines the available endpoints available.

### 3.2. Useful commands

| Command | Description |
|-------------------|------------------------------------------------------------------------------------------------------------------------------------------|
Expand All @@ -100,7 +107,7 @@ yarn start

<sup>[Back to top ^][table-of-contents]</sup>

### 3.2. Docker Compose service directory
### 3.3. Docker Compose service directory

Here is a list of all the localhost port mappings for each of the apps

Expand Down
2 changes: 1 addition & 1 deletion src/enums/APIPathEnum.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
enum APIPathEnum {
API = 'api',
Chains = 'chains',
Docs = 'docs',
Fees = 'fees',
Versions = 'versions',
}
Expand Down
8 changes: 7 additions & 1 deletion src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,13 @@ import type { IEnvironmentVariables, ILogLevel } from '@app/types';

// utils
import createLoggerService from '@app/utils/createLoggerService';
import parseVersion from '@app/utils/parseVersion';

(async () => {
let app: NestApplication;
let configService: ConfigService<IEnvironmentVariables, true>;
let logger: LoggerService;
let versions: string[];

try {
app = await NestFactory.create(AppModule);
Expand All @@ -28,6 +30,9 @@ import createLoggerService from '@app/utils/createLoggerService';
configService.get<string>(EnvironmentVariableKeyEnum.AppName),
configService.get<ILogLevel>(EnvironmentVariableKeyEnum.LogLevel)
);
versions = parseVersion(
configService.get<string>(EnvironmentVariableKeyEnum.AppVersion)
);

// setup middleware
app.useLogger(logger);
Expand All @@ -40,11 +45,12 @@ import createLoggerService from '@app/utils/createLoggerService';
},
})
);
app.setGlobalPrefix(`${APIPathEnum.API}/v${versions[0]}`);
app.useGlobalPipes(new ValidationPipe()); // for validating query params

// setup open api
SwaggerModule.setup(
APIPathEnum.Docs,
APIPathEnum.API,
app,
SwaggerModule.createDocument(
app,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ export default class DatabaseConnectionResponseBodyDTO {
public readonly status: ConnectionStatusEnum;
@ApiProperty({
description: 'The type of database.',
enum: ConnectionStatusEnum,
enumName: 'ConnectionStatusEnum',
})
public readonly type: string;
@ApiProperty({
Expand Down
1 change: 1 addition & 0 deletions src/modules/versions/dtos/VersionResponseBodyDTO.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ interface IProps {
export default class VersionResponseBodyDTO {
@ApiProperty({
description: 'Database connection information.',
type: DatabaseConnectionResponseBodyDTO,
})
public readonly databases: DatabaseConnectionResponseBodyDTO[];
@ApiProperty({
Expand Down
1 change: 1 addition & 0 deletions src/utils/parseVersion/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export { default } from './parseVersion';
5 changes: 5 additions & 0 deletions src/utils/parseVersion/parseVersion.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
export default function parseVersion(version: string): string[] {
const sanitizedVersion: string = version.replace(/[^\d.]/g, '');

return sanitizedVersion.split('.');
}

0 comments on commit a8daf4e

Please sign in to comment.