How to use the redoc.loadAndBundleSpec function in redoc

To help you get started, weā€™ve selected a few redoc examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github Redocly / redoc / cli / index.ts View on Github external
async function serve(port: number, pathToSpec: string, options: Options = {}) {
  let spec = await loadAndBundleSpec(pathToSpec);
  let pageHTML = await getPageHTML(spec, pathToSpec, options);

  const server = createServer((request, response) => {
    console.time('GET ' + request.url);
    if (request.url === '/redoc.standalone.js') {
      respondWithGzip(
        createReadStream(join(BUNDLES_DIR, 'redoc.standalone.js'), 'utf8'),
        request,
        response,
        {
          'Content-Type': 'application/javascript',
        },
      );
    } else if (request.url === '/') {
      respondWithGzip(pageHTML, request, response, {
        'Content-Type': 'text/html',
github Redocly / redoc / cli / index.ts View on Github external
const handlePath = async path => {
      try {
        spec = await loadAndBundleSpec(pathToSpec);
        pageHTML = await getPageHTML(spec, pathToSpec, options);
        log('Updated successfully');
      } catch (e) {
        console.error('Error while updating: ', e.message);
      }
    };
github Redocly / redoc / cli / index.ts View on Github external
async function bundle(pathToSpec, options: Options = {}) {
  const start = Date.now();
  const spec = await loadAndBundleSpec(pathToSpec);
  const pageHTML = await getPageHTML(spec, pathToSpec, { ...options, ssr: true });

  mkdirp.sync(dirname(options.output!));
  writeFileSync(options.output!, pageHTML);
  const sizeInKiB = Math.ceil(Buffer.byteLength(pageHTML) / 1024);
  const time = Date.now() - start;
  console.log(
    `\nšŸŽ‰ bundled successfully in: ${options.output!} (${sizeInKiB} KiB) [ā± ${time / 1000}s]`,
  );
}
github maasglobal / maas-tsp-api / utils / bundle-spec.js View on Github external
async function bundleSpec() {
  const dir = path.dirname(out);
  if (!fs.existsSync(dir)) {
    fs.mkdirSync(dir, { recursive: true });
  }
  const json = await loadAndBundleSpec(spec);
  fs.writeFileSync(out, JSON.stringify(json, null, 2));
}
github maasglobal / maas-tsp-api / src / index.js View on Github external
app.get('/specs/booking.json', async (req, res) =>
  loadAndBundleSpec('./specs/booking.yml').then(json => res.json(json))
);

redoc

ReDoc

MIT
Latest version published 15 days ago

Package Health Score

91 / 100
Full package analysis