Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Rails route for api on subdomain

Tags:

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?

like image 401
smek Avatar asked Aug 01 '12 15:08

smek


1 Answers

Change

namespace :api, defaults: {format: 'json'} do

to

namespace :api, path: nil, defaults: {format: 'json'} do
like image 131
Ruxton Avatar answered Sep 19 '22 14:09

Ruxton