Caminho de source map inválido na instalação de subpasta

My subfolder install kept giving errors in Firefox console about the fact that it is unable to find source maps.

Source map error: request failed with status 404 Resource URL: [https://redacted.com/community/assets/admin-…1d82fc1b0c7d1f24b7b71256a4eb4860f1aa96444925a361d8c24425c.js](https://redacted.com/community/assets/admin-e1c3cbc1d82fc1b0c7d1f24b7b71256a4eb4860f1aa96444925a361d8c24425c.js) Source Map URL: /assets/admin-e1c3cbc1d82fc1b0c7d1f24b7b71256a4eb4860f1aa96444925a361d8c24425c.js.map

As you can see, the /community path prefix is missing from the source map URL.

So I did a little digging.

lib/tasks/assets.rake does this:

  assets = cdn_relative_path("/assets")
  source_map_root = assets + ((d = File.dirname(from)) == "." ? "" : "/#{d}")

Now cdn_relative_path in lib/global_path.rb looks like this.

module GlobalPath
  def path(p)
    "#{GlobalSetting.relative_url_root}#{p}"
  end

  def cdn_path(p)
    GlobalSetting.cdn_url.blank? ? p : "#{GlobalSetting.cdn_url}#{path(p)}"
  end

  def upload_cdn_path(p)
    if SiteSetting.Upload.s3_cdn_url.present?
      p = Discourse.store.cdn_url(p)
    end

    (p =~ /^http/ || p =~ /^\/\//) ? p : cdn_path(p)
  end

  def cdn_relative_path(path)
    if (cdn_url = GlobalSetting.cdn_url).present?
      URI.parse(cdn_url).path + path
    else
      path
    end
  end

As you can see, both cdn_path and upload_cdn_path eventually call the path method which makes sure that the subfolder is being prefixed. However, cdn_relative_path does not call the path method, it just returns its parameter (called… path).

BTW I think cdn_path needs to return path(p) in the middle part of the ternary as well?

1 curtida

@sam is the expert on source maps

@david has fussed with this in the past, but yeah getting the paths right for CDN + subfolder is not easy. I am open to a PR that fixes it provided this is very targeted at your magic combo and does not regress any places that work now.

3 curtidas

@sam Temos alguma solução para esse problema com um source map incorreto? Estou com o mesmo problema em uma instalação em subpasta e com o CDN Fastly.

Minha recomendação é apenas esperar um pouco; estamos migrando para o Ember CLI, que substituirá todo esse pipeline.

2 curtidas

@sam Quando vamos migrar para o Ember CLI? Temos o mesmo problema com instalação em subpasta e o Fastly CDN.

Essa mudança está em andamento; você já pode desenvolver localmente usando o Ember CLI. Mais alguns meses e estará pronto.

2 curtidas

Acredito que isso deva ser resolvido com o ember-cli? @david você saberia dizer se esse é o caso?

2 curtidas

Sim, fiz várias melhorias no source-map nas últimas semanas, que se aplicam a ambos os pipelines ‘legacy’ e Ember-CLI.

Acabei de verificar um dos nossos sites hospedados em subpasta no tests-passed, e as coisas parecem estar funcionando muito melhor :ok_hand:

5 curtidas

Este tópico foi automaticamente fechado após 12 dias. Novas respostas não são mais permitidas.