-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
8 changed files
with
196 additions
and
16 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
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 |
---|---|---|
@@ -1,4 +1,6 @@ | ||
{ | ||
"singleQuote": true, | ||
"trailingComma": "all" | ||
} | ||
"trailingComma": "all", | ||
"printWidth": 120, | ||
"useTabs": false | ||
} |
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,19 @@ | ||
export interface IAppConfig { | ||
port: number; | ||
apiPrefix: string; | ||
useOpenApi: boolean; | ||
dbHost: string; | ||
dbPort: number; | ||
dbUsername: string; | ||
dbPassword: string; | ||
dbName: string; | ||
} | ||
|
||
export default (): Partial<IAppConfig> => ({ | ||
port: 4100, | ||
apiPrefix: '/api', | ||
useOpenApi: true, | ||
dbHost: 'localhost', | ||
dbPort: 5432, | ||
dbName: 'cat-cafe', | ||
}); |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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
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 |
---|---|---|
@@ -1,8 +1,29 @@ | ||
import { NestFactory } from '@nestjs/core'; | ||
import { AppModule } from './app.module'; | ||
import { ConfigService } from '@nestjs/config'; | ||
import { DocumentBuilder, SwaggerModule } from '@nestjs/swagger'; | ||
import * as packageInfo from '../package.json'; | ||
|
||
async function bootstrap() { | ||
const app = await NestFactory.create(AppModule); | ||
await app.listen(3000); | ||
|
||
const configService = app.get(ConfigService); | ||
const apiPrefix = configService.get<string>('apiPrefix', 'api'); | ||
const useOpenApi = configService.get<boolean>('useOpenApi', false); | ||
|
||
if (useOpenApi) { | ||
const options = new DocumentBuilder() | ||
.setTitle(packageInfo.name) | ||
.setDescription(`${packageInfo.name} API`) | ||
.setVersion(packageInfo.version) | ||
.build(); | ||
|
||
const document = SwaggerModule.createDocument(app, options); | ||
SwaggerModule.setup(`${apiPrefix}/openapi`, app, document); | ||
} | ||
|
||
app.setGlobalPrefix(apiPrefix); | ||
await app.listen(configService.get<number>('port') || 3000); | ||
} | ||
|
||
bootstrap(); |
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