Skip to content

Commit

Permalink
Add BASE_PATH environment variable
Browse files Browse the repository at this point in the history
  • Loading branch information
moisses89 committed Oct 3, 2023
1 parent f90c594 commit 1ec6066
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 5 deletions.
1 change: 1 addition & 0 deletions .env.sample
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,4 @@ ADMIN_EMAIL=admin@safe
ADMIN_PASSWORD=password
WEBHOOKS_CACHE_TTL=300000
NODE_ENV=dev
#BASE_PATH=/test # Set a globlal url path
5 changes: 4 additions & 1 deletion src/admin/adminjs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,15 @@ async function buildAdminJsModule() {
const { AdminModule } = await (eval(
`import('@adminjs/nestjs')`,
) as Promise<any>);
const basePath = (process.env.BASE_PATH || '') + '/admin';
return AdminModule.createAdminAsync({
imports: [AuthModule],
inject: [AuthService],
useFactory: (authService: AuthService) => ({
adminJsOptions: {
rootPath: '/admin',
rootPath: basePath,
loginPath: basePath + '/login',
logoutPath: basePath + '/logout',
resources: [Webhook],
},
auth: {
Expand Down
9 changes: 5 additions & 4 deletions src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,15 @@ import { INestApplication } from '@nestjs/common';
/**
* Configure swagger for app
*/
function setupSwagger(app: INestApplication) {
function setupSwagger(app: INestApplication, basePath: string) {
const config = new DocumentBuilder()
.setTitle('Safe Events Service')
.setDescription('Safe Events Service API')
.setVersion('1.0')
// .addTag('safe')
.build();
const document = SwaggerModule.createDocument(app, config);
SwaggerModule.setup('', app, document);
SwaggerModule.setup(basePath, app, document);
}

async function bootstrap() {
Expand All @@ -28,8 +28,9 @@ async function bootstrap() {
})
: ['verbose', 'debug', 'log', 'error', 'warn'],
});

setupSwagger(app);
const basePath = process.env.BASE_PATH || '';
app.setGlobalPrefix(basePath);
setupSwagger(app, basePath);
await app.listen(3000);
}
bootstrap();

0 comments on commit 1ec6066

Please sign in to comment.