@@ -5,8 +5,8 @@ const fs = BBPromise.promisifyAll(require('fs'));
55const path = require ( 'path' ) ;
66const HTTPError = require ( '../lib/util.js' ) . HTTPError ;
77
8- // Swagger-ui helpfully exporting the absolute path of its dist directory
9- const docRoot = `${ require ( 'swagger-ui' ) . dist } /` ;
8+ // Swagger-ui-dist helpfully exporting the absolute path of its dist directory
9+ const docRoot = `${ require ( 'swagger-ui-dist ' ) . getAbsoluteFSPath ( ) } /` ;
1010
1111function processRequest ( app , req , res ) {
1212
@@ -27,25 +27,48 @@ function processRequest(app, req, res) {
2727 return fs . readFileAsync ( filePath )
2828 . then ( ( body ) => {
2929 if ( reqPath === '/index.html' ) {
30+ const css = `
31+ /* Removes Swagger's image from the header bar */
32+ .topbar-wrapper .link img {
33+ display: none;
34+ }
35+ /* Adds the application's name in the header bar */
36+ .topbar-wrapper .link::after {
37+ content: "${ app . info . name } ";
38+ }
39+ /* Removes input field and explore button from header bar */
40+ .swagger-ui .topbar .download-url-wrapper {
41+ display: none;
42+ }
43+ /* Modifies the font in the information area */
44+ .swagger-ui .info li, .swagger-ui .info p, .swagger-ui .info table, .swagger-ui .info a {
45+ font-size: 16px;
46+ line-height: 1.4em;
47+ }
48+ /* Removes authorize button and section */
49+ .scheme-container {
50+ display: none
51+ }
52+ ` ;
3053 body = body . toString ( )
3154 . replace ( / ( (?: s r c | h r e f ) = [ ' " ] ) / g, '$1?doc&path=' )
3255 // Some self-promotion
33- . replace ( / < a i d = " l o g o " .* ?< \/ a > / ,
34- `<a id="logo" href="${ app . info . homepage } ">${ app . info . name } </a>` )
56+ . replace ( / < \/ s t y l e > / , `${ css } \n </style>` )
3557 . replace ( / < t i t l e > [ ^ < ] * < \/ t i t l e > / , `<title>${ app . info . name } </title>` )
3658 // Replace the default url with ours, switch off validation &
3759 // limit the size of documents to apply syntax highlighting to
38- . replace ( / d o c E x p a n s i o n : " n o n e " / , 'docExpansion : "list ", ' +
39- 'validatorUrl: null, ' +
40- 'highlightSizeThreshold: 10000' )
41- . replace ( / u r l : u r l , / , 'url: "/?spec", ') ;
60+ . replace ( / d o m _ i d : ' # s w a g g e r - u i ' / , 'dom_id : "#swagger-ui ", ' +
61+ 'docExpansion: "none", defaultModelsExpandDepth: -1, validatorUrl: null, displayRequestDuration: true' )
62+ . replace ( / " h t t p s : \/ \/ p e t s t o r e . s w a g g e r . i o \/ v 2 \/ s w a g g e r . j s o n " / ,
63+ ' "/?spec"') ;
4264 }
4365
4466 let contentType = 'text/html' ;
4567 if ( / \. j s $ / . test ( reqPath ) ) {
4668 contentType = 'text/javascript' ;
4769 body = body . toString ( )
48- . replace ( / u n d e r s c o r e - m i n \. m a p / , '?doc&path=lib/underscore-min.map' ) ;
70+ . replace ( / u n d e r s c o r e - m i n \. m a p / , '?doc&path=lib/underscore-min.map' )
71+ . replace ( / s o u r c e M a p p i n g U R L = / , 'sourceMappingURL=/?doc&path=' ) ;
4972 } else if ( / \. p n g $ / . test ( reqPath ) ) {
5073 contentType = 'image/png' ;
5174 } else if ( / \. m a p $ / . test ( reqPath ) ) {
@@ -54,11 +77,13 @@ function processRequest(app, req, res) {
5477 contentType = 'application/x-font-ttf' ;
5578 } else if ( / \. c s s $ / . test ( reqPath ) ) {
5679 contentType = 'text/css' ;
57- body = body . toString ( ) . replace ( / \. \. \/ ( i m a g e s | f o n t s ) \/ / g, '?doc&path=$1/' ) ;
80+ body = body . toString ( )
81+ . replace ( / \. \. \/ ( i m a g e s | f o n t s ) \/ / g, '?doc&path=$1/' )
82+ . replace ( / s o u r c e M a p p i n g U R L = / , 'sourceMappingURL=/?doc&path=' ) ;
5883 }
5984
6085 res . setHeader ( 'Content-Type' , contentType ) ;
61- res . setHeader ( 'content-security-policy ' , "default-src 'none'; " +
86+ res . setHeader ( 'Content-Security-Policy ' , "default-src 'none'; " +
6287 "script-src 'self' 'unsafe-inline'; connect-src *; " +
6388 "style-src 'self' 'unsafe-inline'; img-src 'self'; font-src 'self';" ) ;
6489 res . send ( body . toString ( ) ) ;
0 commit comments