3

我有一个带有 ActiveModelAdapter 的 ember-cli 应用程序到使用rack-cors的 Rails API 。我已将两者都配置为使用ember-cli-simple-auth-devise

在本地开发中,一切正常。但是,一旦我将 ember-cli 应用程序部署到 Heroku,我就无法验证我的登录,但能够检索其他记录。我收到以下 405 错误:

POST http://example.herokuapp.com/businesses/sign_in 405(不允许)

也许这与我在我的设计模型中使用 Business 而不是 User 的事实有关,但是我在 application_controller 中将 User 更改为 Business (另外它不会在本地工作):

## /backend/app/controllers/application_controller.rb

class ApplicationController < ActionController::Base
 before_filter :authenticate_user_from_token!

 private

 def authenticate_user_from_token!
   authenticate_with_http_token do |token, options|
     user_email = options[:user_email].presence
     user       = user_email && Business.find_by_email(user_email) 
     ## /\ Changed User to Business /\

     if user && Devise.secure_compare(user.authentication_token, token)
       sign_in user, store: false
     end
   end
 end
end

机架配置:

## /backend/config.ru

require ::File.expand_path('../config/environment',  __FILE__)
run Rails.application

require 'rack/cors'
use Rack::Cors do

  # allow all origins in development
  allow do
    origins '*'
    resource '*', 
        :headers => :any, 
        :methods => [:get, :post, :delete, :put, :options]
  end
end

我已经像这样配置了 simple-auth-devise:

// frontend/config/environment.js

ENV['simple-auth-devise'] = {
    serverTokenEndpoint: 'businesses/sign_in',
    resourceName: 'business',
    crossOriginWhitelist: ['http://example-backend.herokuapp.com/']
};

对此的任何见解将不胜感激。

谢谢!

**更新** 我已将其范围缩小到它是一个 POST 到 example.herokuapp.com 而不是我的 rails 后端 URL 的 example-backend.herokuapp.com 的事实。所以我认为这与 ember-cli-simple-auth 不使用我在 heroku 中设置的代理有关,就像商店正在做的那样。

4

1 回答 1

2

serverTokenEndpoint当主机不是提供 Ember 应用程序的主机时,您需要配置包括主机:

ENV['simple-auth-devise'] = {
  serverTokenEndpoint:  'http://example-backend.herokuapp.com/businesses/sign_in',
  resourceName:         'business',
  crossOriginWhitelist: ['http://example-backend.herokuapp.com/']
};
于 2014-10-17T21:09:28.723 回答