Browse Source

fix: pass auth token in redoc swagger json request

Signed-off-by: Pranav C <pranavxc@gmail.com>
pull/4431/head
Pranav C 2 years ago
parent
commit
3da67d77d5
  1. 31
      packages/nocodb/src/lib/meta/api/swagger/redocHtml.ts

31
packages/nocodb/src/lib/meta/api/swagger/redocHtml.ts

@ -17,8 +17,33 @@ export default `<!DOCTYPE html>
</style>
</head>
<body>
<redoc spec-url='./swagger.json'></redoc>
<script src="https://cdn.jsdelivr.net/npm/redoc@latest/bundles/redoc.standalone.js"> </script>
<div id="redoc"></div>
<script src="https://cdn.jsdelivr.net/npm/redoc@latest/bundles/redoc.standalone.js"></script>
<script>
let initialLocalStorage = {}
try {
initialLocalStorage = JSON.parse(localStorage.getItem('nocodb-gui-v2') || '{}');
} catch (e) {
console.error('Failed to parse local storage', e);
}
const xhttp = new XMLHttpRequest();
xhttp.open("GET", "./swagger.json");
xhttp.setRequestHeader("Content-Type", "application/json;charset=UTF-8");
xhttp.setRequestHeader("xc-auth", initialLocalStorage && initialLocalStorage.token);
xhttp.onload = function () {
const swaggerJson = this.responseText;
const swagger = JSON.parse(swaggerJson);
Redoc.init(swagger, {
scrollYOffset: 50
}, document.getElementById('redoc'))
};
xhttp.send();
</script>
<script>
console.log('%c🚀 We are Hiring!!! 🚀%c\\n%cJoin the forces http://careers.nocodb.com', 'color:#1348ba;font-size:3rem;padding:20px;', 'display:none', 'font-size:1.5rem;padding:20px')
const linkEl = document.createElement('a')
@ -61,4 +86,4 @@ export default `<!DOCTYPE html>
setTimeout(() => linkEl.classList.add('active'), 2000)
</script>
</body>
</html>`;
</html>`

Loading…
Cancel
Save