Is it possible to emulate remote URL behavior using local browser object?

167 views Asked by At

I am using Redoc standalone with our API server. After redoc.standalone.js is loaded, redoc tries to fetch schema.yaml from the API server. However, our server needs an Authorization header with token, which Redoc does not include by default. I am looking for a solution to either download and save the schema file locally or add the Authorization header as a default header for all requests sent from the page. Is there another way to read schema.yaml locally by Redoc without making a request to the private API server? Below is the current HTML code I am using with Redoc:

<!DOCTYPE html>
<html>
   <head>
      <title>Example API</title>
      <meta charset="utf-8"/>
      <meta name="viewport" content="width=device-width, initial-scale=1">
      <link href="https://fonts.googleapis.com/css?family=Montserrat:300,400,700|Roboto:300,400,700" rel="stylesheet">
      <style>
         body {
         margin: 0;
         padding: 0;
         }
      </style>
   </head>
   <body>
      <redoc spec-url='https://api.example.com/schema.yaml'></redoc>
      <script src="redoc.standalone.js"></script>
   </body>
</html>
1

There are 1 answers

2
Lorna Mitchell On

I think this can be done with a different approach. Instead of using the react rendering with Redoc, build the HTML documentation with the redocly build-docs command (see docs: https://redocly.com/docs/cli/commands/build-docs/) from a location where you do have access to the schema, or can download it before generating the docs. Then publish the HTML output.

(disclaimer, I work at Redocly, who make Redoc)