简体   繁体   English

如何从生成的 URL 中删除端口? 导轨

[英]How can I remove the port from generated URLs? rails

I'm having a problem where my app is generating links from mailers to www.myurl.herokuapp.com/:8080/someurl - and that's breaking all my links, as they work, but not with the :8080 added.我有一个问题,我的应用程序生成从邮件程序到 www.myurl.herokuapp.com/:8080/someurl 的链接 - 这破坏了我的所有链接,因为它们可以工作,但没有添加 :8080。 ie if I manually remove the /:8080/ it works fine.即如果我手动删除 /:8080/ 它工作正常。

For example, the reset password generated url that's emailed is:例如,通过电子邮件发送的重置密码生成的 url 是:

https://myurl.herokuapp.com/:8080/users/password/edit?reset_password_token=123token123 https://myurl.herokuapp.com/:8080/users/password/edit?reset_password_token=123token123

However, it works fine in development, it's just production where there's an issue.但是,它在开发中运行良好,只是在生产中存在问题。 I've managed to hack it by using static urls for some URLs, but for password reset and long-term health I need to fix it.我已经设法通过对某些 URL 使用静态 url 来破解它,但是为了密码重置和长期健康,我需要修复它。

I'm using: Ruby 2.3.1 Rails 5.1.4 Heroku PGSQL SendInBlue as a mailer我正在使用:Ruby 2.3.1 Rails 5.1.4 Heroku PGSQL SendInBlue 作为邮件程序

What i've tried:我试过的:

In reset_password_instructions.html.erb:在 reset_password_instructions.html.erb 中:

Changing the line from:从以下位置更改行:

<p><%= link_to 'Change my password', edit_password_path(@resource, reset_password_token: @token) %></p>

I've also tried removing the default port from production.rb:我还尝试从 production.rb 中删除默认端口:

config.action_mailer.default_url_options = { host: ' http://myurl.herokuapp.com/ ' } config.action_mailer.default_url_options = { 主机:' http://myurl.herokuapp.com/ ' }

Can anyone advise what might be causing this or how to fix it?任何人都可以建议可能导致此问题的原因或如何解决它?

Error message:错误信息:

The page you were looking for doesn't exist.
You may have mistyped the address or the page may have moved.

If you are the application owner check the logs for more information.

Logs don't seem to throw anything new when clicking on the link in the email, in fact they don't generate anything (?), the last thing in the logs:单击电子邮件中的链接时,日志似乎不会抛出任何新内容,实际上它们不会生成任何内容 (?),即日志中的最后一件事:

2018-09-25T21:16:06.581471+00:00 heroku[web.1]: Stopping all processes with SIGTERM
2018-09-25T21:16:06.709308+00:00 heroku[web.1]: Process exited with status 143
2018-09-25T21:27:39.622506+00:00 heroku[router]: at=info method=GET path="/szallodak/4909;;;" host=staging.herokuapp.com request_id=0eb96201-d562-46d2-93aa-759324d0c64d fwd="95.216.157.196" dyno=web.1 connect=0ms service=6ms status=301 bytes=170 protocol=http
2018-09-25T21:27:41.361516+00:00 heroku[router]: at=info method=GET path="/szallodak/4909" host=staging.herokuapp.com request_id=cdc1c6e4-ce66-404c-a4a7-ed8a7c7eb677 fwd="95.216.157.196" dyno=web.1 connect=0ms service=132ms status=404 bytes=1966 protocol=https
2018-09-25T21:27:41.227565+00:00 app[web.1]: [cdc1c6e4-ce66-404c-a4a7-ed8a7c7eb677] Started GET "/szallodak/4909" for 95.216.157.196 at 2018-09-25 21:27:41 +0000
2018-09-25T21:27:41.355281+00:00 app[web.1]: [cdc1c6e4-ce66-404c-a4a7-ed8a7c7eb677]
2018-09-25T21:27:41.355383+00:00 app[web.1]: [cdc1c6e4-ce66-404c-a4a7-ed8a7c7eb677] ActionController::RoutingError (No route matches [GET] "/szallodak/4909"):
2018-09-25T21:27:41.355437+00:00 app[web.1]: [cdc1c6e4-ce66-404c-a4a7-ed8a7c7eb677]
2018-09-25T21:27:41.355533+00:00 app[web.1]: [cdc1c6e4-ce66-404c-a4a7-ed8a7c7eb677] vendor/bundle/ruby/2.4.0/gems/actionpack-5.1.6/lib/action_dispatch/middleware/show_exceptions.rb:31:in `call'
2018-09-25T21:27:41.355535+00:00 app[web.1]: [cdc1c6e4-ce66-404c-a4a7-ed8a7c7eb677] vendor/bundle/ruby/2.4.0/gems/railties-5.1.6/lib/rails/rack/logger.rb:36:in `call_app'
2018-09-25T21:27:41.355530+00:00 app[web.1]: [cdc1c6e4-ce66-404c-a4a7-ed8a7c7eb677] vendor/bundle/ruby/2.4.0/gems/actionpack-5.1.6/lib/action_dispatch/middleware/debug_exceptions.rb:63:in `call'
2018-09-25T21:27:41.355537+00:00 app[web.1]: [cdc1c6e4-ce66-404c-a4a7-ed8a7c7eb677] vendor/bundle/ruby/2.4.0/gems/railties-5.1.6/lib/rails/rack/logger.rb:24:in `block in call'
2018-09-25T21:27:41.355539+00:00 app[web.1]: [cdc1c6e4-ce66-404c-a4a7-ed8a7c7eb677] vendor/bundle/ruby/2.4.0/gems/activesupport-5.1.6/lib/active_support/tagged_logging.rb:69:in `block in tagged'
2018-09-25T21:27:41.355540+00:00 app[web.1]: [cdc1c6e4-ce66-404c-a4a7-ed8a7c7eb677] vendor/bundle/ruby/2.4.0/gems/activesupport-5.1.6/lib/active_support/tagged_logging.rb:26:in `tagged'
2018-09-25T21:27:41.355542+00:00 app[web.1]: [cdc1c6e4-ce66-404c-a4a7-ed8a7c7eb677] vendor/bundle/ruby/2.4.0/gems/activesupport-5.1.6/lib/active_support/tagged_logging.rb:69:in `tagged'
2018-09-25T21:27:41.355544+00:00 app[web.1]: [cdc1c6e4-ce66-404c-a4a7-ed8a7c7eb677] vendor/bundle/ruby/2.4.0/gems/railties-5.1.6/lib/rails/rack/logger.rb:24:in `call'
2018-09-25T21:27:41.355545+00:00 app[web.1]: [cdc1c6e4-ce66-404c-a4a7-ed8a7c7eb677] vendor/bundle/ruby/2.4.0/gems/actionpack-5.1.6/lib/action_dispatch/middleware/remote_ip.rb:79:in `call'
2018-09-25T21:27:41.355547+00:00 app[web.1]: [cdc1c6e4-ce66-404c-a4a7-ed8a7c7eb677] vendor/bundle/ruby/2.4.0/gems/actionpack-5.1.6/lib/action_dispatch/middleware/request_id.rb:25:in `call'
2018-09-25T21:27:41.355548+00:00 app[web.1]: [cdc1c6e4-ce66-404c-a4a7-ed8a7c7eb677] vendor/bundle/ruby/2.4.0/gems/rack-2.0.5/lib/rack/method_override.rb:22:in `call'
2018-09-25T21:27:41.355550+00:00 app[web.1]: [cdc1c6e4-ce66-404c-a4a7-ed8a7c7eb677] vendor/bundle/ruby/2.4.0/gems/rack-2.0.5/lib/rack/runtime.rb:22:in `call'
2018-09-25T21:27:41.355552+00:00 app[web.1]: [cdc1c6e4-ce66-404c-a4a7-ed8a7c7eb677] vendor/bundle/ruby/2.4.0/gems/activesupport-5.1.6/lib/active_support/cache/strategy/local_cache_middleware.rb:27:in `call'
2018-09-25T21:27:41.355554+00:00 app[web.1]: [cdc1c6e4-ce66-404c-a4a7-ed8a7c7eb677] vendor/bundle/ruby/2.4.0/gems/actionpack-5.1.6/lib/action_dispatch/middleware/executor.rb:12:in `call'
2018-09-25T21:27:41.355555+00:00 app[web.1]: [cdc1c6e4-ce66-404c-a4a7-ed8a7c7eb677] vendor/bundle/ruby/2.4.0/gems/actionpack-5.1.6/lib/action_dispatch/middleware/static.rb:125:in `call'
2018-09-25T21:27:41.355557+00:00 app[web.1]: [cdc1c6e4-ce66-404c-a4a7-ed8a7c7eb677] vendor/bundle/ruby/2.4.0/gems/rack-2.0.5/lib/rack/sendfile.rb:111:in `call'
2018-09-25T21:27:41.355558+00:00 app[web.1]: [cdc1c6e4-ce66-404c-a4a7-ed8a7c7eb677] vendor/bundle/ruby/2.4.0/gems/actionpack-5.1.6/lib/action_dispatch/middleware/ssl.rb:68:in `call'
2018-09-25T21:27:41.355560+00:00 app[web.1]: [cdc1c6e4-ce66-404c-a4a7-ed8a7c7eb677] vendor/bundle/ruby/2.4.0/gems/railties-5.1.6/lib/rails/engine.rb:522:in `call'
2018-09-25T21:27:41.355561+00:00 app[web.1]: [cdc1c6e4-ce66-404c-a4a7-ed8a7c7eb677] vendor/bundle/ruby/2.4.0/gems/puma-3.12.0/lib/puma/configuration.rb:225:in `call'
2018-09-25T21:27:41.355563+00:00 app[web.1]: [cdc1c6e4-ce66-404c-a4a7-ed8a7c7eb677] vendor/bundle/ruby/2.4.0/gems/puma-3.12.0/lib/puma/server.rb:658:in `handle_request'
2018-09-25T21:27:41.355564+00:00 app[web.1]: [cdc1c6e4-ce66-404c-a4a7-ed8a7c7eb677] vendor/bundle/ruby/2.4.0/gems/puma-3.12.0/lib/puma/server.rb:472:in `process_client'
2018-09-25T21:27:41.355566+00:00 app[web.1]: [cdc1c6e4-ce66-404c-a4a7-ed8a7c7eb677] vendor/bundle/ruby/2.4.0/gems/puma-3.12.0/lib/puma/server.rb:332:in `block in run'
2018-09-25T21:27:41.355568+00:00 app[web.1]: [cdc1c6e4-ce66-404c-a4a7-ed8a7c7eb677] vendor/bundle/ruby/2.4.0/gems/puma-3.12.0/lib/puma/thread_pool.rb:133:in `block in spawn_thread'
2018-09-25T21:27:41.657427+00:00 heroku[router]: at=info method=GET path="/szallodak/4909;;;" host=staging.herokuapp.com request_id=47227af4-6a27-4265-8f9f-357d89889a92 fwd="95.216.157.196" dyno=web.1 connect=0ms service=3ms status=301 bytes=170 protocol=http

Very easy fix for anyone else with the same issue, in production.rb I simply added: ",protocol: 'https'" so it now reads:对于遇到相同问题的其他人来说,非常容易修复,在 production.rb 中,我只是简单地添加了:",protocol: 'https'" 所以它现在显示为:

config.action_mailer.default_url_options = { host: 'http://myapp.herokuapp.com',
     protocol: 'https' }

If your protocol isn't https, then you'd simply use http://如果您的协议不是 https,那么您只需使用 http://

I also reverted (though I didn't test it using path) the path, both should work:我还恢复了(虽然我没有使用路径测试它)路径,两者都应该有效:

<p><%= link_to 'Change my password', edit_password_path(@resource, reset_password_token: @token) %></p>

to

<p><%= link_to 'Change my password', edit_password_url(@resource, reset_password_token: @token) %></p>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM