Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Solution for Headers on Null Error in info.blade.phpduring iDoc Documentation Rendering #47

Open
hassaans208 opened this issue Nov 30, 2024 · 0 comments

Comments

@hassaans208
Copy link

Got it! Here's a more detailed and improved explanation of the problem, including the updated context about the baseUrl and its effect:


Solution for Headers on Null Error in info.blade.php during iDoc Documentation Rendering on Production

Problem Explanation:

I encountered an issue while deploying the application to production. During testing on the local environment, everything functioned smoothly and the documentation appeared correctly. However, once the application was deployed to production, an error was encountered while rendering info.blade.php in the iDoc documentation:

Error Message:

Cannot read headers on null

Context:

  • Local Environment: The application worked fine with no errors.
  • Production Environment: The error occurred.

Steps to Reproduce:

  1. Deploy the application to the production environment.
  2. Try to fetch the URL https://localhost:8000/idoc/info.

Identified Root Cause:

The issue was identified in the JavaScript code within the resources/views/documentation.blade.php file where the headers were being set. Specifically, the following code was causing the issue:

The problem was not with the environment itself but with the baseUrl. In the production environment, the baseUrl included api, which caused the if statement to evaluate to true and set the headers, resulting in the error.

if (/\/api/.test(arguments[0]) && !arguments[1].headers.Accept) {
  arguments[1].headers.Accept = 'application/json';
}

Solution:

Removing the problematic JavaScript code that sets the header resolved the issue. The updated resources/views/documentation.blade.php file should look like this:

<!DOCTYPE html>
<html>
  <head>
    <title>{{config('idoc.title')}}</title>
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <style>
      @import url(//fonts.googleapis.com/css?family=Roboto:400,700);

      body {
        margin: 0;
        padding: 0;
        font-family: Verdana, Geneva, sans-serif;
      }

      #redoc_container .menu-content img {
        padding: 0px 0px 30px 0px;
      }
    </style>
    <link rel="icon" type="image/png" href="/favicon.ico">
    <link rel="apple-touch-icon-precomposed" href="/favicon.ico">
  </head>
  <body>
    <div id="redoc_container"></div>
    <script src="https://cdn.jsdelivr.net/npm/@redoc/redoc-pro@1.0.0-beta.38/dist/redocpro-standalone.min.js"></script>
    <script>
      RedocPro.init(
        "{{config('idoc.output') . "/openapi.json"}}", {
          "showConsole": true,
          "pathInMiddlePanel": true,
          "redocExport": "RedocPro",
          "layout": { "scope": "section" },
          "unstable_externalDescription": '{{route(config('idoc.external_description') ?: 'idoc.info')}}',
          "hideDownloadButton" : {{config('idoc.hide_download_button') ?: 0}}
        },
        document.getElementById("redoc_container")
      );

      var constantMock = window.fetch;
      window.fetch = function() {
        return constantMock.apply this, arguments)
      }
    </script>
  </body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant