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

Demo pages don't work for private content #79

Open
akzincsystems opened this issue Feb 1, 2021 · 6 comments
Open

Demo pages don't work for private content #79

akzincsystems opened this issue Feb 1, 2021 · 6 comments

Comments

@akzincsystems
Copy link

Just tried your home page demo with a file:/// uri and with a https:// url that only I can see from my location.

neither works.

Does that mean that hidden behind the scenes your javascript is calling a server that want's to connect to those resources?

Not finding anything here to help me use this locally (or within a build chain, my main priority).

Any suggestions gratefully received.

Thanks

@mrin9
Copy link
Owner

mrin9 commented Feb 5, 2021

well, checkout the QuickStart section,

you need to create an HTML with the following content

<!doctype html>
  <html>
  <head>
    <script src="https://unpkg.com/rapipdf/dist/rapipdf-min.js"></script>
  </head>
  <body>
    <rapi-pdf
      spec-url = "path/of/your/spec/file"
      button-bg = "#b44646" 
    > </rapi-pdf>
  </body> 
  </html>

place this html, on a server from where you can access your spec.
the other option would be to upload your spec to a public location such as github, and try to use that for generation

@akzincsystems
Copy link
Author

I used the quickstart section as a guide.

if I have

<!doctype html>
<html>
<head>
    <script src="https://unpkg.com/rapipdf/dist/rapipdf-min.js"></script>
</head>
<body>
<rapi-pdf
        spec-url = "file:///home/me/docs/openapi.yml"
        button-bg = "#b44646"
> </rapi-pdf>
</body>
</html>

It doesn't work. Nor does
spec-url = "/home/me/docs/openapi.yml"

The page is displayed with a button. Clicking the button does nothing. Error in console is

rapipdf-min.js:8673 Fetch API cannot load file:///home/akitson/Projects/Synapse/api-logon-service/docs/openapi.yml. URL scheme must be "http" or "https" for CORS request.

Changing the spec-url to https://docs.ops.zinc.systems/authentication.yml (only I can see this url) gives

Access to fetch at 'https://docs.ops.zinc.systems/authentication.yml' from origin 'null' has been blocked by CORS policy: No 'Access-Control-Allow-Origin' header is present on the requested resource. If an opaque response serves your needs, set the request's mode to 'no-cors' to fetch the resource with CORS disabled.

So, your fetch mechanism doesn't recognise a local file. That will make the app difficult to use in a build chain.

CORS is more problematic and is possibly due to the browser, rather than your code. Do you have a way of running this locally in a script? I don't see any tests so cannot determine how to run it locally.

@mrin9
Copy link
Owner

mrin9 commented Feb 9, 2021

can you try a relative url
have the html and spec file in the same location and specify spec-url="./openapi.yml"

something like this

<!doctype html>
<html>
<head>
    <script src="https://unpkg.com/rapipdf/dist/rapipdf-min.js"></script>
</head>
<body>
    <rapi-pdf spec-url = "./openapi.yml"> </rapi-pdf>
</body>
</html>

@akzincsystems
Copy link
Author

Same issue using relative path:
Fetch API cannot load file:///home/akitson/Projects/Misc/architecture/openapi.yml. URL scheme must be "http" or "https" for CORS request.

Uncaught (in promise) TypeError: Cannot read property 'paths' of undefined

So for a file path, it is still trying to do a CORS request

@akzincsystems
Copy link
Author

I disabled CORS in the browser as per https://alfilatov.com/posts/run-chrome-without-cors/ and still get the CORS error above. This perhaps suggest that CORS is being handled in the code rather than the browser.

@cfecherolle
Copy link

I found a (not automated) way to generate docs, if your spec does not contain any sensitive data you can upload your file as a JSON bin on a site such as: https://www.npoint.io/

With your content uploaded and available through a public URL with properly-set CORS restrictions in response headers, the lib should work as expected. Hope it helps someone!

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

3 participants