config/initializers/apartment/subdomain_exclusions.rb
Apartment::Elevators::Subdomain.excluded_subdomains = ['www']
Above doesn't seems to be working. I'm using rails 5.0.2.
in apartment.rb I have this
Apartment::Elevators::Subdomain.excluded_subdomains = ['www', 'admin']
Rails.application.config.middleware.use'Apartment::Elevators::Subdomain'
To test on local i have added hosts
127.0.0.1 www.example.com admin.example.com
on www.example.com I got error Apartment::TenantNotFound
What I'm missing here.
Related
I just set up cloudflare ssl on top of my website, and now whenever redirect_to #thing is called in rails the client redirects to https://subdomain/thing/1 rather than https://subdomain.domain.com/thing/1. not sure if I need to change the cloudflare A records now that ssl is setup because the A record I had before CNAME | subdomain | host isn't working anymore. If any more information is necessary please let me know!
Rails server is started like so rails s -p 3000 -b0.0.0.0 -e production
DNS records are
CNAME | subdomain | host
A | domain | serverip
A | www | serverip
The rails server is running at serverip:3000 and nginx is routing all traffic with the specific subdomain to this port. There are no redirect issues if everything is done using serverip:3000, but when I do actions using subdomain.domain.com the redirect issues reappear
nginx config
```
server {
listen 80;
server_name subdomain.domain.com;
location / {
proxy_pass http://subdomain;
}
}
upstream subdomain {
server 127.0.0.1:3000;
}
```
you can add following changes routes.rb
constraints subdomain: false do
get ':any', to: redirect(subdomain: 'www', path: '/%{any}'), any: /.*/
end
You can set the number of top-level domains as an argument to subdomain, e.g:
>> app.get('http://www.localhost')
>> app.request.subdomain
=> ""
>> app.request.subdomain(0)
=> "www"
This can also be set in an environment file as well:
# config/environments/development.rb
config.action_dispatch.tld_length = 0
O configure my Ruby on Rails application to use sentry with error report, but it show-me this error:
URI::InvalidURIError:
bad URI(is not URI?): 'http://9ba0c50c55c94603a488a55516d5xxx:xxxx6d6468a4cb892140c1f86a9f228#sentry.myaddres.com/24'
When I remove 9ba0c50c55c94603a488a55516d5xxx:xxxx6d6468a4cb892140c1f86a9f228# this part of addresss all works fine, but in sentry documentation is:
Raven.configure do |config|
config.dsn = 'http://public:secret#example.com/project-id'
end
How can I solve this problem?
I was using ENV var to set sentry DSN:
# .env
SENTRY_DSN_URL='http://public:secret#example.com/project-id'
and in initializer
Raven.configure do |config|
config.dsn = ENV['SENTRY_DSN']
end
This problem is the quotation marks. To solve just remove them.
# .env
SENTRY_DSN_URL=http://public:secret#example.com/project-id
Works fine.
I have problems figuring out the good way to set up the host/port for test on CircleCI
EDIT 2 - Requirements :
Rails app running locally on TEST_PORT (if available in ENV variable) or on default port 3000
I have session based tests, so magically switching from localhost to 127.0.0.1 will cause test failures
On my CircleCI environment I mapped host www.example.com to 127.0.0.1 and I'd like Capybara to connect to that website instead of directly localhost/127.0.0.1
On my CircleCI environment the port 80 is reserved so the rails app HAS to run on a different port (like 3042)
Some integration tests need to connect to remote website (Sorry no VCR yet) www.example-remote.com on port 80
Previously my test suite was running fine with localhost:3042 but then I realized I had problems with tests that used session : the rails app itself started on localhost but then emails were sent to the 127.0.0.1 address which caused session-based tests to fail
I changed the following config
# feature/env.rb
Capybara.server_port = ENV['TEST_PORT'] || 3042
Rails.application.routes.default_url_options[:port] = Capybara.server_port
if ENV['CIRCLECI']
Capybara.default_host = 'http://www.example.com/'
end
# configuration/test.rb
config.action_mailer.default_url_options = {
host: (ENV['CIRCLECI'].present? ? 'www.example.com' : '127.0.0.1'),
port: ENV['TEST_PORT'] || 3042
}
# circle.yml
machine:
hosts:
www.example.com: 127.0.0.1
But now I'm getting weird email urls being generated like http://www.example.com/:3042/xxx
Did someone manage a working configuration on circleCI using custom host name ?
EDIT
Capybara 2.13
Rails 5.0
Cucumber 2.4
CircleCI 1.x
Capybara.default_host only affects tests using the rack_test driver (and only if Capybara.app_host isn't set). It shouldn't have the trailing '/' on it, and it already defaults to 'http://www.example.com' so your setting of it should be unnecessary.
If what you're trying to do is make all your tests (JS and non-JS) go to 'http://www.example.com' by default then you should be able to do either
Capybara.server_host = 'www.example.com'
or
Capybara.app_host = 'http://www.example.com'
Capybara.always_include_port = true
My new config which seems to work for session-based tests but fails for remote websites (it tries to reach the remote server with the same TEST_PORT I have defined (eg click on email with http://www.example-remote.com/some_path --> Capybara connects to http://www.example-remote.com:TEST_PORT/some_path)
# features/env.rb
# If test port specified, use it
if ENV['TEST_PORT'].present?
Capybara.server_port = ENV['TEST_PORT']
elsif ActionMailer::Base.default_url_options[:port].try do |port|
Capybara.server_port = port
end
else
Rails.logger.warn 'Capybara server port could not be inferred'
end
# Note that Capybara needs either an IP or a URL with http://
# Most TEST_HOST env variable will only include domain name
def set_capybara_host
host = [
ENV['TEST_HOST'],
ActionMailer::Base.default_url_options[:host]
].detect(&:present?)
if host.present?
# If the host is an IP, Capybara.app_host = IP will crash so do nothing
return if host =~ /^[\d\.]+/
# If hostname starts with http(s)
if host =~ %r(^(?:https?\:\/\/)|(?:\d+))
# OK
elsif Capybara.server_port == 443
host = 'https://' + host
else
host = 'http://' + host
end
puts "Attempting to set Capybara host to #{host}"
Capybara.app_host = host
else
Rails.logger.warn 'Capybara server host could not be inferred'
end
end
set_capybara_host
# config/environments/test.rb
Capybara.always_include_port = true
config.action_mailer.default_url_options = {
host: (ENV['TEST_HOST'].present? ? ENV['TEST_HOST'] : '127.0.0.1'),
port: (ENV['TEST_PORT'].present? ? ENV['TEST_PORT'] : 3042)
}
I am using Oauth to connect to facebook, and it works fine for local development.
I want to run this on Heroku however, and there I get this error:
2012-06-14T15:50:16+00:00 app[web.1]: Errno::ENOENT (No such file or directory - Certificate file "/opt/local/share/curl/curl-ca-bundle.crt" does not exist!):
2012-06-14T15:50:16+00:00 app[web.1]: app/controllers/sharing_controller.rb:138:in `facebook_callback'
I have configured the SSL endpoint in Heroku but that did not change anything.
I figured it out -
I had to change the Koala cert path parameter:
Old:
Koala.http_service.ca_file = '/opt/local/share/curl/curl-ca-bundle.crt'
New:
Koala.http_service.ca_file = '/usr/lib/ssl/certs/ca-certificates.crt'
I have a grails app running on a tomcat server that is pointed to by apache 2.2 http server. Using mod_jk I've gotten it to work using myapp.com:9090 to get to the app. However myapp.com just gives me 503 with the error:
"Could not reliably determine the server's fully qualified domain name, using 193.xx.xxx.xxx for ServerName."
But this is the only error I get.
The virtual host looks like this:
<VirtualHost 193.xx.xxx.xxx:80>
ServerName www.myapp.se
ServerAlias myapp.se
DocumentRoot "D:/apache-tomcat-7.0.5/webapps/ROOT"
JkMount /* worker1
</VirtualHost>
In the httpd.conf i load the module like this:
# Load module
LoadModule jk_module modules/mod_jk.so
# Where to find workers.properties
JkWorkersFile conf/workers.properties
# Where to put jk logs
JkLogFile logs/mod_jk.log
# Set the jk log level [debug/error/info]
JkLogLevel emerg
# Select the log format
JkLogStampFormat "[%a %b %d %H:%M:%S %Y] "
# JkOptions indicate to send SSL KEY SIZE,
JkOptions +ForwardKeySize +ForwardURICompat -ForwardDirectories
# JkRequestLogFormat set the request format
JkRequestLogFormat "%w %V %T"
And the workers.properties looks like this:
workers.tomcat_home="D:/apache-tomcat-7.0.5"
workers.java_home="C:/Program Files/Java/jdk1.6.0_22"
ps=/
worker.list=worker1
worker.worker1.port=8010
worker.worker1.host=localhost
worker.worker1.type=ajp13
worker.worker1.lbfactor=1
Have you tried mod_proxy_ajp? I have a Grails app in production that uses Apache 2.2, Tomcat 6x, Grails 1.3.7 with Apache proxying to Tomcat w/o issue using mod_proxy_ajp. If you're not restricted to using mod_jk, I recommend giving this a try. And I have this working on Centos 5.5, Ubuntu 10.4LTS and Win2k3 environments, FYI.