From 2a04d87f12d1c77097bf3b6aefa16a31ffb7552d Mon Sep 17 00:00:00 2001 From: Seth Wheeler <23089578+Megapixel99@users.noreply.github.com> Date: Fri, 18 Oct 2024 17:51:01 -0500 Subject: [PATCH] feat: Enable use of CDN --- lib/ui.js | 10 +++++----- test/index.js | 20 ++++++++++++++++++++ 2 files changed, 25 insertions(+), 5 deletions(-) diff --git a/lib/ui.js b/lib/ui.js index d2c2469..ee18130 100644 --- a/lib/ui.js +++ b/lib/ui.js @@ -3,7 +3,7 @@ const path = require('path') const serve = require('serve-static') module.exports.serveSwaggerUI = function serveSwaggerUI (documentUrl, opts = {}) { - const { plugins, ...options } = opts + const { plugins, cdnBaseUrl, ...options } = opts return [serve(path.resolve(require.resolve('swagger-ui-dist'), '..'), { index: false }), function returnUiInit (req, res, next) { @@ -24,12 +24,12 @@ module.exports.serveSwaggerUI = function serveSwaggerUI (documentUrl, opts = {}) }, function renderSwaggerHtml (req, res) { res.type('html').send(renderHtmlPage('Swagger UI', ` - + `, `
- - - + + + `)) } ] diff --git a/test/index.js b/test/index.js index 77122ef..d813450 100644 --- a/test/index.js +++ b/test/index.js @@ -653,6 +653,26 @@ suite(name, function () { }) }) + test('use a CDN', (done) => { + const app = express() + const oapi = openapi(undefined, { basePath: '/base-path' }) + + app.use(oapi) + + app.get(oapi.routePrefix, oapi.swaggerui({ cdnBaseUrl: 'https://notARealURL' })) + + supertest(app) + .get(oapi.routePrefix) + .expect(200, (err, res) => { + assert(!err, err) + assert(res.text.includes('')) + assert(res.text.includes('')) + assert(res.text.includes('')) + assert(res.text.includes('')) + done() + }) + }) + // Other tests require('./_validate')() require('./_routes')()