Ember POST 405 (not allowed) w / Rails API

I get POST https://heroku_client_path.herokuapp.com/login 405 (Not Allowed) for the Ember.js app with Rails api (both on the hero)

When processing login or registration. I feel that the request URL should be the heroku server address / login, as I set my config ADAPTER_URL heroku config, not the heroku client url shown above.

I believe that I have the correct CORS setting.

I am using Ember-CLI. I passed auth, it's not just Auth.

environment.js:

 module.exports = function(environment) { var ENV = { modulePrefix: 'client-rantly', environment: environment, baseURL: '/', adapterURL: process.env.ADAPTER_URL, locationType: 'auto', EmberENV: { FEATURES: { } }, }; if (environment === 'development') { } if (environment === 'production') { } return ENV; }; 

adapters / application.js:

 import DS from 'ember-data'; import ENV from '../config/environment'; export default DS.ActiveModelAdapter.extend({ host: ENV.adapterURL || ENV.ADAPTER_URL, headers: function () { return { 'auth_token': localStorage.getItem('authToken') }; }.property('authToken') }); 

brocfile.js

 var EmberApp = require('ember-cli/lib/broccoli/ember-app'); var app = new EmberApp({ dotEnv: { clientAllowedKeys: ['ADAPTER_URL'] } }); module.exports = app.toTree(); 

Controllers / application.js

 import Ember from 'ember'; export default Ember.Controller.extend({ needs: ['search'], isAuthenticated: false, init: function() { var authToken = localStorage.getItem('authToken'); if(authToken) { this.isAuthenticated = true; } }, actions: { login: function () { var credentials = { email: this.get('email'), password: this.get('password') }; this.set('errorMessage', null); return Ember.$.post('login', credentials).then(function(response){ this.set('errorMessage', response.error); if (response.auth_token) { localStorage.setItem('authToken', response.auth_token); localStorage.setItem('userId', response.user_id); this.set('isAuthenticated', true); location.reload(); } }.bind(this)); }, } }); 

cors rails side - config / application.rb

 require File.expand_path('../boot', __FILE__) require 'rails/all' Bundler.require(*Rails.groups) module ServerRantly class Application < Rails::Application config.active_record.raise_in_transactional_callbacks = true config.autoload_paths << Rails.root.join('lib') config.middleware.insert_before 0, "Rack::Cors", :debug => true, :logger => (-> { Rails.logger }) do allow do origins '*' resource '/cors', :headers => :any, :methods => [:post], :credentials => true, :max_age => 0 resource '*', :headers => :any, :methods => [:get, :post, :delete, :put, :options, :head], :max_age => 0 end end end end 
+7
ruby-on-rails cors ember-cli heroku
source share
1 answer

In this line:

 adapterURL: process.env.ADAPTER_URL 

Where is process.env.ADAPTER_URL indicated?

It seems that you are on the right track with overriding host on the ActiveModelAdapter adapter to use your ActiveModelAdapter -client url.

+1
source share

All Articles