我想让我的 Rails 应用程序的 API 可以通过子域 (https://api.domain.com) 访问。我定义了以下路线:
constraints :subdomain => 'api' do
namespace :api, defaults: {format: 'json'} do
scope module: :v1, constraints: ApiConstraints.new(version: 1, default: true) do
resources :posts
end
end
end
这可行,但会产生以下网址:
https://api.domain.com/api/posts
我希望它是:
https://api.domain.com/posts
API 控制器位于app/controllers/api/v1中它们应该保留的位置。
我尝试绘制路线但没有任何成功。有人知道如何解决这个问题吗?