405 not allowed nginx, CORS? Nginx config? Or something else? - ruby-on-rails

Working on an app built using Ember.js and Rails.
Authentication is being done with ember-simple-auth using Oauth2.
I am able to login to my app locally in my development environment, but as soon as I try to login on my production server (through Heroku) I start receiving a nginx 405 not allowed status code.
First thing I thought was maybe it is my request headers / CORS. I am using rack-cors gem on my rails side and configured it based directly off the readme example. Here is my application.rb
Researching, I found the same problem with the solution being to configure Nginx side of things, but I figured since that is being handled by heroku I wasn't really sure if that was where I need to make my changes.
Let me know if there are any other files/info that could help.
What is the best way to debug this problem?

Try using this first to rule out CORS:
https://chrome.google.com/webstore/detail/allow-control-allow-origi/nlfbmbojpeacfghkpbjhddihlkkiljbi
Does the route work locally when you use Postman or a similar tool?
Are you requesting HTML or JSON?

Related

Rails loopback/redirection issue in production

I am new to Rails, Currently I am working on Rails application which is back-end and Angular as a front end. I am getting an issue like in my production server when I go to backend(rails) URL, it redirects me to root URL of application and return 502 for every rails request. I have checked CORS but not any issue in it. Same code is working find in my local development enviornment.
Can anyone help me to find this issue?

Prevent SSL on subdomains

I have my main app (Ruby on Rails) hosted with Heroku, DNS managed by DNSimple. It is served using SSL with a wildcard certificate. myapp.com and www.myapp.com, both work correctly.
The issue starts when I try and direct some subdomains to other services. For example I want blog.myapp.com to point to our instance of Ghost.org. I am also trying to point data.myapp.com to a different heroku app that we use for reporting purposes.
I don't need/want either of these subdomains to use SSL but it seems no matter what I try, that they try and fail to load the HTTPS version.
To be honest I'm confused where this is being triggered from. Where should I be altering the configuration. My Rails App, Heroku, DNSimple, the SSL cert, somewhere else entirely?
I have managed to solve this issue by clearing the browser cache on my machine.
I'm not sure what caused it to force SSL to begin with but the current configuration seems to be now be working.

Why cant I read headers after updating to rails 4.2.0

I have an app I recently upgraded to Rails 4.2.0. In this app I request an access token for a small API. In the API controller I am attempting to grab this token. I am testing with POSTman, sending a request to my local machine, running it with dev or production works perfect fine. Sending a request to the nginx phusion passenger server yields nothing, the token is nil according to the logs.
POSTman request
headers: access_token: '12345'
API controller
#access_token = request.headers['HTTP_ACCESS_TOKEN']
The headers are read in all cap with the http prefix as I read somewhere - which I can't seem to find now, that this was the proper setup. My rails 3.2 app used to read lowercase without the prefix headers, and work correctly. Once upgrading to 4.2.0, this functionality broke locally. Adding the prefix and uppercasing the read-in solved the issue locally in dev and production modes. Once deployed, however, the headers always seem to be nil.
Since I can run locally in production mode and this works, I am having a hard time figuring out what happens once this is deployed. Is this something with nginx or passenger? I am pretty new to nginx, am I missing something here? Any help you could provide would be greatly appreciated.
When using rails over an Webserver with CGI Interface, these Headers are dropped by Apache or NGIX.
It's a legacy problem. ACCESS-TOKEN and ACCESS_TOKEN would be mapped to the same CGI variable 'access_token'.
And because Dashes are more common in the header, the underscores are ignored.

Redirection in RubyOnRails

I just got an SSL certificate for "example.com". After making some configurations in NGINX I could finally redirect "http://www.example.com" calls and "http://example.com" calls to "https://example.com". Everything works fine, but when I type "https://www.example.com" an SSL error is shown. Is there a way to redirect "https://www.example.com" calls to "https://example.com" using some Ruby code?
Handling the redirect at the Rack level and not inside of the Rails app is my preferred way to solve this requirement.
https://github.com/jtrupiano/rack-rewrite#scheme
The link takes you to the part of the README that addresses this question. I've used this gem in the past and it works really well.

Rails get production environment working with SSL on local machin

I am having trouble with my site with precompiled assets looking nothing like my site with assets served on-the-go. So I figured, I should try things out in production.
Here's the problem, when I do, I get:
!! Invalid request
in my terminal log and in my browser I see
Error 107 (net::ERR_SSL_PROTOCOL_ERROR): SSL protocol error.
The graphic designer is not amused at the mess thats up right now, and I'd love to be able to reproduce the problem. Any ideas on how to get past this SSL issue?
The only way that I've ever been able to get sites implementing SSL working on my development box in production mode has been to set up Apache in front of my rails server (Webrick, or whatever). This is kind of a pain to set up, but it works. You should be able to find a guide on how to set it up using your exact configuration with a quick search. Another option would be to enable SSL via a configuration file, instead of by environment, so you could simply disable it regardless of your current environment. This is assuming everything else is actually correct and working...

Resources