-
-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(export): separate running the app from boostrapping it
this will allow apps to import achievibit and use it as a sub path
- Loading branch information
1 parent
a9131e5
commit 5669934
Showing
2 changed files
with
53 additions
and
50 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,50 @@ | ||
import { ValidationPipe } from '@nestjs/common'; | ||
import { NestFactory } from '@nestjs/core'; | ||
import { NestExpressApplication } from '@nestjs/platform-express'; | ||
import { DocumentBuilder, SwaggerModule } from '@nestjs/swagger'; | ||
import { readFileSync } from 'fs-extra'; | ||
import nunjucks from 'nunjucks'; | ||
import { join } from 'path'; | ||
|
||
import { AppModule } from '@kb-app'; | ||
import { ConfigService } from '@kb-config'; | ||
import { PackageDetailsDto } from '@kb-models'; | ||
|
||
export async function bootstrap(): Promise<NestExpressApplication> { | ||
const config = new ConfigService(); | ||
|
||
const app = await NestFactory.create<NestExpressApplication>(AppModule); | ||
app.useGlobalPipes(new ValidationPipe({ | ||
whitelist: true | ||
})); | ||
|
||
const packageDetails: PackageDetailsDto = | ||
await app.get('AppService').getPackageDetails(); | ||
|
||
const options = new DocumentBuilder() | ||
.setTitle(packageDetails.name) | ||
.setDescription('The achievibit API description') | ||
.setVersion(packageDetails.version) | ||
.build(); | ||
|
||
const document = SwaggerModule.createDocument(app, options); | ||
// SwaggerModule.setup('api/docs', app, document); | ||
|
||
SwaggerModule.setup('api/docs', app, document, { | ||
customSiteTitle: `kibibit - achievibit API documentation`, | ||
customCss: readFileSync(join(__dirname, '../public/swagger.css'), 'utf8') | ||
// customJs: '../swagger-things/swagger.js', | ||
// customfavIcon: '../swagger-things/favicon-32.png' | ||
}); | ||
|
||
app.useStaticAssets(join(__dirname, '..', 'public'), { prefix: '/public/' }); | ||
app.setBaseViewsDir(join(__dirname, '..', 'views')); | ||
app.setViewEngine('njk'); | ||
nunjucks.configure('views', { | ||
autoescape: true, | ||
express: app, | ||
watch: true | ||
}); | ||
|
||
return app; | ||
} |
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,51 +1,4 @@ | ||
import { ValidationPipe } from '@nestjs/common'; | ||
import { NestFactory } from '@nestjs/core'; | ||
import { NestExpressApplication } from '@nestjs/platform-express'; | ||
import { DocumentBuilder, SwaggerModule } from '@nestjs/swagger'; | ||
import { readFileSync } from 'fs-extra'; | ||
import nunjucks from 'nunjucks'; | ||
import { join } from 'path'; | ||
import { bootstrap } from './bootstrap-application'; | ||
|
||
import { AppModule } from '@kb-app'; | ||
import { ConfigService } from '@kb-config'; | ||
import { PackageDetailsDto } from '@kb-models'; | ||
|
||
async function bootstrap() { | ||
const config = new ConfigService(); | ||
|
||
const app = await NestFactory.create<NestExpressApplication>(AppModule); | ||
app.useGlobalPipes(new ValidationPipe({ | ||
whitelist: true | ||
})); | ||
|
||
const packageDetails: PackageDetailsDto = | ||
await app.get('AppService').getPackageDetails(); | ||
|
||
const options = new DocumentBuilder() | ||
.setTitle(packageDetails.name) | ||
.setDescription('The achievibit API description') | ||
.setVersion(packageDetails.version) | ||
.build(); | ||
|
||
const document = SwaggerModule.createDocument(app, options); | ||
// SwaggerModule.setup('api/docs', app, document); | ||
|
||
SwaggerModule.setup('api/docs', app, document, { | ||
customSiteTitle: `kibibit - achievibit API documentation`, | ||
customCss: readFileSync(join(__dirname, '../public/swagger.css'), 'utf8') | ||
// customJs: '../swagger-things/swagger.js', | ||
// customfavIcon: '../swagger-things/favicon-32.png' | ||
}); | ||
|
||
app.useStaticAssets(join(__dirname, '..', 'public'), { prefix: '/public/' }); | ||
app.setBaseViewsDir(join(__dirname, '..', 'views')); | ||
app.setViewEngine('njk'); | ||
nunjucks.configure('views', { | ||
autoescape: true, | ||
express: app, | ||
watch: true | ||
}); | ||
|
||
await app.listen(config.port); | ||
} | ||
bootstrap(); | ||
bootstrap() | ||
.then((app) => app.listen(10101)); |