CloudCannon / pagefind

Static low-bandwidth search at scale
https://pagefind.app
MIT License
3.48k stars 113 forks source link

basePath being set relative to server root. Browser not able to load due to CORS? #168

Open paulstroot opened 1 year ago

paulstroot commented 1 year ago

I'm implementing PageFind into a Gatsby project, and initializing it using the JS API, like this:

const p = await import( "../public/_pagefind/pagefind.js");

The issue I'm having is that the browser is outputting the following error when pagefind is initialized (this is when I am developing on localhose:8000)

Not allowed to load local resource (Chrome)
Cross origin requests are only supported for HTTP. (Safari)

The issue seems to be when the basePath is set in initPrimary() on line 568. It is setting basePath relative to the server root. Everything loads perfectly if I simply eliminate the call to "initPrimary()'. This of course is not a good solution because pagefind.js gets rebuilt every time I reindex the site. Is there a way around this?

bglw commented 1 year ago

Hello!

Hmm, I'll see if I can find a way to reproduce this — with a cursory test it seems to work fine for me. I assume the issue is the ../ section of the path — does it work when an absolute path is supplied? (starting with /)

paulstroot commented 1 year ago

I have set up a minimal reproduction here. https://github.com/paulstroot/pagefind_gatsby_test

I'm realizing that I may have some other issues to work out regarding how I'm indexing and loading PageFind in the context of a Gatsby project. I could not find any examples of using PageFind with Gatsby, so I'm going to post a new issue asking for some help with that. Once that is worked out. I will continue with this issue if it still persists, or close it.

Here is my other issue for reference: #171