Ambiente di sviluppo: la porta mancante causa immagini interrotte

I configured a logo in the site settings, but the logo’s URL is missing the default port, i.e. the logo URL looks like this http://localhost/uploads/… rather than http://localhost:3000/uploads/….

I’m starting the development server like this:

RAILS_ENV=development bundle exec rails server

I found that Discourse.base_url is set to "http://localhost" and in config/database.yml, I find this note for the development.hostnames key:

### Don't include the port number here.
Change the "port" site setting instead, at /admin/site_settings.

However, such a site setting does not exist. What do I do?

It’s a hidden setting. Try changing it in the rails console.

bin/rails c

SiteSetting.port = 3000

This works, thank you.

Shouldn’t this be set to 3000 by default in development mode?

No, I don’t think so. Not everyone is using port 3000 for development.

It’s the default, though, isn’t it? That one has to set the hidden port setting is not at all obvious, hence seeing a logo in the development environment not load is unexpected. In other words, setting a custom logo should just work.

Logos work. It’s not something you usually care about in development.

Alternatively, I believe you can use these entries in sitesettings.yml

developer:
  force_hostname:
    hidden: false
    default: '<my-ip>'
  port:
    hidden: false
    default: '<my-port>'

@pfaffman gave me that tip! (and what a life saver that was)

Ho avuto il problema opposto a quello dell’originale poster durante la configurazione di un sito di sviluppo ieri: sto eseguendo il mio server di sviluppo dietro un proxy Nginx, quindi desidero URL puliti, ma non importa cosa cambiavo nelle impostazioni, Discourse continuava ad aggiungere :3000 a molti dei miei link interni, incluso il logo del sito. Alla fine ho individuato il problema nelle righe 291-293 di lib/discourse.rb:

if Rails.env.development? && SiteSetting.port.blank?
    url << ":#{ENV["UNICORN_PORT"] || 3000}"
end

Commentando queste righe, il logo e gli altri link hanno funzionato correttamente, anche se non so se questo possa causare altri problemi in futuro. Sembra un po’ controintuitivo sovrascrivere SiteSetting.port in questo modo.

Ho sperimentato un po’ di più con questo e sembra che tutto funzioni correttamente se imposto semplicemente SiteSetting.port = 443 e seleziono anche la casella per ‘forza https’ (e immagino che funzionerebbe anche con la porta 80 e senza https). Avevo letto da qualche parte che avrei dovuto lasciare le impostazioni della porta vuote, ma immagino che fosse un consiglio sbagliato.