Add a remote schema on Hasura from localhost rails server fails - ruby-on-rails

I am testing Hasura with docker on my localhost, and I would like to add a remote schema, from a graphql endpoint on my local environment (rails app, http://localhost:3000/graphql)
When I try to add the remote schema URL on Hasura (via http://host.docker.internal:3000/graphql), it fails with the following message:
Adding remote schema failed
Error in $: Failed reading: not a valid json value at '<!DOCTYPEhtml>'
And, I have no log on my rails server.
I tried to use ngrok to have an https endpoint, (https://6e12fa99336b.ngrok.io forwarding to localhost:3000) but I had the same message. My ngrok console did show a post to /graphql, with 403 Forbidden, and still no log on the rails server
However it works with a public external API (https://countries.trevorblades.com/graphql for instance)
Is there something that I am doing wrong, some headers missing ?

Ok, finally got it ! The issue was with rails, not having host.docker.internal as a registered host, thus rendering an HTML error page.
After adding host.docker.internal to config.host everything worked.

Related

Testing Twilio with ngrok tunnel to localhost results in bad host name error

In the past I've used ngrok to test twilio webhooks on my local machine - it's always worked. I'm working on a new app that uses Co-Pilot (not sure if it has anything to do with co-pilot) and I'm getting the 11210 error: HTTP bad host name.
I initialize my tunnel with /Applications/ngrok http -host-header=rewrite local.whicheversiteimworkingon.com:80
The URL listed in the Message Text is http://fcd0ed57.ngrok.io/sms/twilio/incoming but the body shows
Twilio was unable to fetch content from: https://local.thesiteimworkingon.com/sms/twilio/incoming
Error: Unknown host local.thesiteimworkingon.com
Account SID: AC5a22f090b458f6942da879d347451dfd
SID: SM9c45741b5b70967df6a7e196e3bee552
Request ID: 9fde222c-14e1-448e-ad79-4a392d212ffd
Remote Host: local.thesiteimworkingon.com
Request Method: POST
Request URI: https://local.thesiteimworkingon.com/sms/twilio/incoming
SSL Version: TLSv1.2
URL Fragment: true
Unfortunately I don't have an example of this from when it was working - it's been months (maybe 12+) since I've had to do this.
[Update] I've confirmed this happens with co-pilot and regular numbers, starting to think it's environment related.
Have I misconfigured something in order to test this locally?
Can you try the https ngrok instead of http?
Twilio developer evangelist here.
It may be to do with the application server you are using expecting a different host name. When you start Ngrok, you can pass the --host-header flag to rewrite the host header for your application.
ngrok http 3000 --host-header=rewrite local.domain.com
Let me know if that helps at all.

How does one develop a Shopify App in a local Rails environment?

I've been having some trouble trying to set up a Shopify app so that I can develop it in my local Rails environment.
I've followed the documentation HERE but when I install the app into my shopify dev store I get an error stating localhost sent an invalid response.
My local rails server log shows:
ERROR bad URI '::�+�/�,�0̨̩�\x14�\x13�\x13�\x14\x00�\x00�\x00/\x005\x00'.
ERROR bad Request-Line '\x16\x03\x01\x00�\x01\x00\x00�\x03\x03d��������\x1F�ŭ����=G�+q\r[��� N�\x00\x00 jj�+�/�,�0̨̩�\x14�\x13�\x13�\x14\x00�\x00�\x00/\x005\x00'.
After digging through other shopify docs I found this:
This says to tunnel with ngrok to avoid problems which makes sense, except that the shopify_app documentation states to specify http://localhost:3000 as the application URL and http://localhost:3000/auth/shopify/callback as the Redirection URL.
Can anyone tell me how to set my Shopify app so I can develop it locally? Or is this something I will have to develop live on heroku?
Ngrok is simply a tunnel to localhost, so you can set your application URL to https://subdomain.ngrok.io and redirection URL as https://subdomain.ngrok.io/auth/shopify/callback. You can configure ngrok to tunnel on port 3000 by specifying the port number when initializing ngrok: ./ngrok http 3000.

Cannot access wsdl file from different machine

I am trying to run the running Client & Server Application on different machine but then I am getting below exception message which says it can not get wsdl file on that machine:
javax.xml.ws.WebServiceException: Failed to access the WSDL at:
http://localhost:8080/proj_name/EmpServices?wsdl. It failed with: Got
http://localhost:8080/proj_name/EmpServices?wsdl while opening stream
from same_link_as_above/EmpServices?wsdl.
It looks like connection issue, not WSDL or service-related.
Possible causes and solutions:
You tell about "remote machine", but errors says "localhost".
Have you configured your service client to work with your remote machine?
Shouldn't it be remote machine's address? Or is it just a typo?
If you configured it correctly, make sure that you have a working connection and port 8080 is allowed in your firewalls.
You may also try to open this link directly in your browser from client machine, and see what is says.
Perhaps, you will get connection error message, while you should get WSDL file.

How do I avoid "preflight requests"?

I am trying to get started with Ember Data and immediately ran into this problem were the browser sends a OPTIONS request before the actual request.
The development backend I am trying to communicate with is a rails 4.2 server running on my local machine (started with rails s -b 0.0.0.0 )
I currently use this api to communicate from both an android and an ios app. My end goal is to provide an Ember app in addition to the existing rails UI, but if I have to replace it and only have the Ember UI, that will be OK.
I did some reading on CORS and I think at at least understand what it is trying to do. If I understand correctly, the browser sees the Ember app as having been served by a server other than the one that requests are being made to and because of this asks the server if this is OK.
So my questions are:
Will I be able to deploy my ember app to the real server such that these CORS OPTIONS requests are not needed? (ie, I assume a rails app can deliver an Ember app to the browser and the browser will see the source of the script as being the same as the target of the request and not require the prefight requests)
How do I get this to work in development? I see there is a --proxy option on the ember s --proxy, which seemed like it was supposed to be the solution for this, but I have not been able to get it to work
When I navigate to the server url I am trying to access http://localhost:3000/api/v1/users rails logs the following response:
Started GET "/api/v1/users" for 127.0.0.1 at 2016-04-17 10:02:01 -0400
Based on this, I think I have my Ember adapter set up correctly:
import JSONAdapter from 'ember-data/adapters/json-api';
export default JSONAdapter.extend({
host: 'http://127.0.0.1:3000',
namespace: 'api/v1'
});
Then I start the Ember server with this command:
ember s --proxy http://127.0.0.1:3000
The rails server is receiving the following request:
Started OPTIONS "/api/v1/users" for 127.0.0.1 at 2016-04-17 09:36:51 -0400
Which fails because I don't have a route for that (and don't think I want to either).
If you use --proxy you should not override your host!
The ember app should make all request to the current endpoint (probably localhost:4200) and the development server will redirect the requests to the backend.
If you:
Want to serve your ember app from your backend server in production, and
want to use --proxy in your development enviroment
don't set host on your adapter and just have fun. If you set host, ember will sent the data directly to this host, and not to your development server, resulting in a CORS request.

API attempt from Heroku results in DNS error 'SocketError: Hostname not known'

I'm running an application on Heroku that attempts to connect to MailChimp using the Gibbon gem (to add an email address to a mailing list). The API connection fails. The Heroku error logs show:
SocketError: getaddrinfo: Name or service not known
I saw a blog post (thanks Mike Subelsky)
that recommends adding require 'resolv-replace.rb' to the application in a config/initializer/requires.rb file, so I tried that. Now the Heroku error logs show:
SocketError: Hostname not known: 8c7d675bb0b8.api.mailchimp.com
I'm not sure where the strange hostname comes from. The host "api.mailchimp.com" exists but "8c7d675bb0b8.api.mailchimp.com" doesn't exist.
The application works in development on my local machine. And other applications on Heroku that use the same code also work without a problem.
What's going on and how can I fix it?
I had this same issue and finally found what was causing it. When I set my api key on Heroku, I was missing the -us4 on the end. The Mailchimp api library splits on the "-" and prepends the us4 to build the api url.

Resources