@@ -2,6 +2,9 @@ import { Logger, ValidationPipe } from "@nestjs/common"
2
2
import { NestFactory } from "@nestjs/core"
3
3
import { SwaggerModule , DocumentBuilder } from "@nestjs/swagger"
4
4
import { ironSession } from "iron-session/express"
5
+ import { stringify } from "yaml"
6
+ import { readFileSync } from "fs"
7
+ import { join } from "path"
5
8
import { AppModule } from "./app/app.module"
6
9
import { GroupsService } from "./app/groups/groups.service"
7
10
@@ -51,80 +54,27 @@ async function bootstrap() {
51
54
52
55
const document = SwaggerModule . createDocument ( app , config )
53
56
57
+ const customJsStr = readFileSync (
58
+ join ( __dirname , "swagger-custom-ui.js" ) ,
59
+ "utf8"
60
+ )
61
+
54
62
const configUI = {
55
63
swaggerOptions : { defaultModelsExpandDepth : - 1 } ,
56
64
customfavIcon :
57
65
"https://raw.githubusercontent.com/bandada-infra/bandada/main/apps/dashboard/src/assets/favicon.ico" ,
58
66
customSiteTitle : "Bandada API Docs" ,
59
67
customCss : `.topbar-wrapper img {content:url('https://raw.githubusercontent.com/bandada-infra/bandada/d5268274cbb93f73a1960e131bff0d2bf1eacea9/apps/dashboard/src/assets/icon1.svg'); width:60px; height:auto;}
60
68
.swagger-ui .topbar { background-color: transparent; } small.version-stamp { display: none !important; }` ,
61
- customJsStr : `
62
- // Add a custom title to the right side of the Swagger UI page
63
- document.addEventListener('DOMContentLoaded', function() {
64
- const customTitle = document.createElement('div');
65
- customTitle.style.position = 'absolute';
66
- customTitle.style.top = '27px';
67
- customTitle.style.padding = '10px';
68
- customTitle.style.color = 'black';
69
- customTitle.style.fontSize = '18px';
70
- customTitle.style.padding = '0 20px';
71
- customTitle.style.maxWidth = '1460px';
72
- customTitle.style.display = 'flex';
73
- customTitle.style.justifyContent = 'end';
74
- customTitle.style.width = '100%';
75
-
76
-
77
- // Create a hyperlink element
78
- const link = document.createElement('a');
79
- link.href = 'https://github.com/bandada-infra/bandada';
80
- link.rel = 'noreferrer noopener nofollow';
81
- link.target = '_blank'
82
- link.style.color = 'grey';
83
- link.style.display = 'flex';
84
-
85
- // Create a text node for the link text
86
- const linkText = document.createTextNode('Github');
87
-
88
- // Append the text node to the link
89
- link.appendChild(linkText);
90
-
91
- // Create an SVG element for the GitHub icon
92
- const githubIcon = document.createElementNS('http://www.w3.org/2000/svg', 'svg');
93
- githubIcon.setAttribute('width', '24');
94
- githubIcon.setAttribute('height', '24');
95
- githubIcon.setAttribute('viewBox', '0 0 20 20');
96
- githubIcon.setAttribute('fill', 'currentColor');
97
-
98
- const path = document.createElementNS('http://www.w3.org/2000/svg', 'path');
99
- path.setAttribute('d', 'M8 .153C3.589.153 0 3.742 0 8.153c0 3.436 2.223 6.358 5.307 7.408.387.071.53-.168.53-.374 0-.185-.007-.674-.01-1.322-2.039.445-2.47-.979-2.47-.979-.334-.849-.815-1.075-.815-1.075-.667-.457.05-.448.05-.448.739.052 1.13.76 1.13.76.656 1.124 1.719.799 2.134.61.067-.478.256-.8.466-.98-1.63-.184-3.34-.815-3.34-3.627 0-.8.287-1.457.754-1.969-.076-.185-.327-.932.072-1.943 0 0 .618-.198 2.03.752a6.74 6.74 0 0 1 1.8-.245c.61.003 1.226.082 1.8.245 1.41-.95 2.027-.752 2.027-.752.4 1.011.148 1.758.073 1.943.47.512.754 1.17.754 1.969 0 2.82-1.712 3.44-3.35 3.623.264.227.497.672.497 1.356 0 .977-.009 1.764-.009 2.004 0 .207.141.449.544.373C13.775 14.511 16 11.59 16 8.154 16 3.743 12.411 .154 8 .154z');
100
-
101
- // Append the path to the GitHub icon
102
- githubIcon.appendChild(path);
103
-
104
- // Append the GitHub icon to the link
105
- link.insertBefore(githubIcon, link.firstChild);
106
-
107
- // Apply some padding to create space between the icon and the text
108
- link.style.paddingLeft = '8px';
109
-
110
- // Append the link to the custom title
111
- customTitle.appendChild(link);
112
-
113
- const parentDiv = document.createElement('div');
114
- parentDiv.style.display = 'flex';
115
- parentDiv.style.justifyContent = 'center';
116
- parentDiv.style.width = 'auto';
117
-
118
-
119
- parentDiv.appendChild(customTitle)
120
-
121
- document.body.appendChild(parentDiv);
122
- });
123
- `
69
+ customJsStr
124
70
}
125
71
126
72
SwaggerModule . setup ( "/" , app , document , configUI )
127
73
74
+ app . getHttpAdapter ( ) . get ( "/openapi.yml" , ( req , res ) => {
75
+ res . type ( "text/yaml" ) . send ( stringify ( document ) )
76
+ } )
77
+
128
78
await app . listen ( port )
129
79
130
80
Logger . log ( `🚀 Application is running on: http://localhost:${ port } ` )
0 commit comments