Rails route for api on subdomain

Viewed 3987

I want to make the API of my Rails app accessible through a subdomain (https://api.domain.com). I have the following routes defined:

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

This works but results in the following url:

https://api.domain.com/api/posts

I would like it to be:

https://api.domain.com/posts

The API controllers are in app/controllers/api/v1 where they should stay.

I tried mapping the route but without any success. Does somebody know how to fix this?

1 Answers
Related