# Problema con il percorso relativo che causa errore CORS sui siti Discourse

**URL:** <https://meta.discourse.org/t/issue-with-relative-path-causing-cors-error-on-discourse-sites/333024>\
**Category:** Bug\
**Created:** [27 Ottobre 2024, 6:27am UTC](https://meta.discourse.org/t/issue-with-relative-path-causing-cors-error-on-discourse-sites/333024 "2024-10-27T06:27:11Z")\
**Posts on this page:** 1\
**Showing post:** 1

<div class="post-metadata">

**Author:** ![Yt.w](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/yt.w/32/348367_2.png) [@Yt.w](https://meta.discourse.org/u/Yt.w)\
**Post date:** [27 Ottobre 2024, 6:27am UTC](https://meta.discourse.org/t/issue-with-relative-path-causing-cors-error-on-discourse-sites/333024/1 "2024-10-27T06:27:11Z")

</div>

Il seguente codice in **lib/highlight\_js.rb** funziona su alcuni domini ma non su altri:

```ruby
def self.path
    "/highlight-js/#{Discourse.current_hostname}/#{version SiteSetting.highlighted_languages}.js"
end

```

Ho due siti Discourse. Questo codice funziona sul dominio `www.abc.com`, ma non funziona su `efg.com`. Nella console del browser, vedo il seguente errore:

`formatter.js:383 Uncaught (in promise) TypeError: Failed to resolve module specifier '/highlight-js/efg.com/9797975efac87d28baa695ae13ca72ccaf5120f5.js'. `The base URL is about:blank because import() is called from a CORS-cross-origin script.

Dopo aver modificato `self.path` in `highlight_js.rb` come segue:

```ruby
def self.path
    "https://#{Discourse.current_hostname}/highlight-js/#{Discourse.current_hostname}/#{version SiteSetting.highlighted_languages}.js"
end

```

il problema è stato risolto.

Sembra che l’utilizzo di un percorso relativo come  
`import('/highlight-js/efg.com/9797975efac87d28baa695ae13ca72ccaf5120f5.js')`  
causi un problema CORS, mentre l’utilizzo di un URL assoluto,  
`import('https://efg.com/highlight-js/efg.com/9797975efac87d28baa695ae13ca72ccaf5120f5.js') `, funzioni correttamente.

---

_[View the full topic](https://meta.discourse.org/t/issue-with-relative-path-causing-cors-error-on-discourse-sites/333024)._
