generated from fastify/skeleton
-
Notifications
You must be signed in to change notification settings - Fork 42
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Relative urls for static content (#164)
Fixes regression where relative urls for the static content became absolute, thus breaking reverse proxy usage. This commit reverts to relative urls for this content, taking into account whether the route that delivers them has a trailing slash or not.
- Loading branch information
1 parent
1f36cee
commit 8796c4c
Showing
3 changed files
with
86 additions
and
31 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 |
---|---|---|
@@ -1,32 +1,35 @@ | ||
'use strict' | ||
|
||
function indexHtml (opts) { | ||
return (url) => `<!-- HTML for static distribution bundle build --> | ||
<!DOCTYPE html> | ||
<html lang="en"> | ||
<head> | ||
<meta charset="UTF-8"> | ||
<title>${opts.theme?.title || 'Swagger UI'}</title> | ||
<link rel="stylesheet" type="text/css" href="${url}${opts.staticPrefix}/swagger-ui.css" /> | ||
<link rel="stylesheet" type="text/css" href="${url}${opts.staticPrefix}/index.css" /> | ||
${opts.theme && opts.theme.css ? opts.theme.css.map(css => `<link rel="stylesheet" type="text/css" href="${url}${opts.staticPrefix}/theme/${css.filename}" />\n`).join('') : ''} | ||
${opts.theme && opts.theme.favicon | ||
? opts.theme.favicon.map(favicon => `<link rel="${favicon.rel}" type="${favicon.type}" href="${url}${opts.staticPrefix}/theme/${favicon.filename}" sizes="${favicon.sizes}" />\n`).join('') | ||
: ` | ||
<link rel="icon" type="image/png" href="${url}${opts.staticPrefix}/favicon-32x32.png" sizes="32x32" /> | ||
<link rel="icon" type="image/png" href="${url}${opts.staticPrefix}/favicon-16x16.png" sizes="16x16" /> | ||
`} | ||
</head> | ||
<body> | ||
<div id="swagger-ui"></div> | ||
<script src="${url}${opts.staticPrefix}/swagger-ui-bundle.js" charset="UTF-8"> </script> | ||
<script src="${url}${opts.staticPrefix}/swagger-ui-standalone-preset.js" charset="UTF-8"> </script> | ||
<script src="${url}${opts.staticPrefix}/swagger-initializer.js" charset="UTF-8"> </script> | ||
${opts.theme && opts.theme.js ? opts.theme.js.map(js => `<script src="${url}${opts.staticPrefix}/theme/${js.filename}" charset="UTF-8"> </script>\n`).join('') : ''} | ||
</body> | ||
</html> | ||
` | ||
return (hasTrailingSlash) => { | ||
const prefix = hasTrailingSlash ? `.${opts.staticPrefix}` : `.${opts.prefix}${opts.staticPrefix}` | ||
return `<!-- HTML for static distribution bundle build --> | ||
<!DOCTYPE html> | ||
<html lang="en"> | ||
<head> | ||
<meta charset="UTF-8"> | ||
<title>${opts.theme?.title || 'Swagger UI'}</title> | ||
<link rel="stylesheet" type="text/css" href="${prefix}/swagger-ui.css" /> | ||
<link rel="stylesheet" type="text/css" href="${prefix}/index.css" /> | ||
${opts.theme && opts.theme.css ? opts.theme.css.map(css => `<link rel="stylesheet" type="text/css" href="${prefix}/theme/${css.filename}" />\n`).join('') : ''} | ||
${opts.theme && opts.theme.favicon | ||
? opts.theme.favicon.map(favicon => `<link rel="${favicon.rel}" type="${favicon.type}" href="${prefix}/theme/${favicon.filename}" sizes="${favicon.sizes}" />\n`).join('') | ||
: ` | ||
<link rel="icon" type="image/png" href="${prefix}/favicon-32x32.png" sizes="32x32" /> | ||
<link rel="icon" type="image/png" href=".${opts.prefix}/favicon-16x16.png" sizes="16x16" /> | ||
`} | ||
</head> | ||
<body> | ||
<div id="swagger-ui"></div> | ||
<script src="${prefix}/swagger-ui-bundle.js" charset="UTF-8"> </script> | ||
<script src="${prefix}/swagger-ui-standalone-preset.js" charset="UTF-8"> </script> | ||
<script src="${prefix}/swagger-initializer.js" charset="UTF-8"> </script> | ||
${opts.theme && opts.theme.js ? opts.theme.js.map(js => `<script src="${prefix}/theme/${js.filename}" charset="UTF-8"> </script>\n`).join('') : ''} | ||
</body> | ||
</html> | ||
` | ||
} | ||
} | ||
|
||
module.exports = indexHtml |
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