Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Setting a dynamic host #222

Open
edwardloveall opened this issue Feb 19, 2016 · 2 comments
Open

Setting a dynamic host #222

edwardloveall opened this issue Feb 19, 2016 · 2 comments

Comments

@edwardloveall
Copy link

I'm creating javascript for customers to embed on their website. The embedded script from my server makes requests to the same server to pull data. If you've ever used Typekit, it's a similar setup, although I'm not serving fonts.

When I deploy, the URL for the app necessarily changes. In Konacha tests, it seems to be 127.0.0.1:[random port]. In my development environment it's localhost:3000. In production, it's the address of my website. I'm using a .js.erb file to construct a dynamic url off of root_url to make sure I'm hitting the right server URL for tests and production and not getting cross origin requests errors.

If I use <%= root_url %>, I get the error:

Missing host to link to! Please provide the :host parameter, set default_url_options[:host], or set :only_path to true

So I need to set the host from the current rails app. In a real development or production environment, I can use request.host_and_port but Konacha doesn't use the rails request object.

So my question is, how can I set the host so it works in both my test, development, and production environments? Am I going about this the wrong way? Is there some way I can access the rails request object during a Konacha test?

@rochej
Copy link

rochej commented Apr 26, 2016

Not sure if this is a hacky solution, but I had the same problem and set my tests to run here:

Rails.application.routes.draw do
mount Konacha::Engine, at: "/konacha" if defined?(Konacha)
end

@edwardloveall
Copy link
Author

@rochej Oh interesting!

So I just tried this and it made all tests work in my development environment, but not for my staging environment. The problem is that my embedded script needs to hit my ever-changing server's address. Mounting konacha fixes the test vs dev environment issue, but I still need to specify the full URL.

Am I understanding this right? How do you hit a different URL when you deploy vs when you test?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants