Merge pull request #748 from metamaps/feature/api-json-404

return 404s for all unmatched api routes
This commit is contained in:
Devin Howard 2016-10-08 14:16:00 +08:00 committed by GitHub
commit ab76b77bdd
8 changed files with 13 additions and 48 deletions

View file

@ -2,11 +2,11 @@
module Api module Api
module V1 module V1
class DeprecatedController < ApplicationController class DeprecatedController < ApplicationController
# rubocop:disable Style/MethodMissing def deprecated
def method_missing render json: {
render json: { error: '/api/v1 is deprecated! Please use /api/v2 instead.' } error: '/api/v1 has been deprecated! Please use /api/v2 instead.'
}, status: :gone
end end
# rubocop:enable Style/MethodMissing
end end
end end
end end

View file

@ -1,7 +0,0 @@
# frozen_string_literal: true
module Api
module V1
class MappingsController < DeprecatedController
end
end
end

View file

@ -1,7 +0,0 @@
# frozen_string_literal: true
module Api
module V1
class MapsController < DeprecatedController
end
end
end

View file

@ -1,7 +0,0 @@
# frozen_string_literal: true
module Api
module V1
class SynapsesController < DeprecatedController
end
end
end

View file

@ -1,7 +0,0 @@
# frozen_string_literal: true
module Api
module V1
class TokensController < DeprecatedController
end
end
end

View file

@ -1,7 +0,0 @@
# frozen_string_literal: true
module Api
module V1
class TopicsController < DeprecatedController
end
end
end

View file

@ -29,6 +29,11 @@ module Api
head :no_content head :no_content
end end
def catch_404
skip_authorization
render json: { error: '404 Not found' }, status: :not_found
end
private private
def accessible_records def accessible_records

View file

@ -77,18 +77,13 @@ Metamaps::Application.routes.draw do
resources :users, only: [:index, :show] do resources :users, only: [:index, :show] do
get :current, on: :collection get :current, on: :collection
end end
match '*path', to: 'restful#catch_404', via: :all
end end
namespace :v1, path: '/v1' do namespace :v1, path: '/v1' do
# api v1 routes all lead to a deprecation error method root to: 'deprecated#deprecated', via: :all
# see app/controllers/api/v1/deprecated_controller.rb match '*path', to: 'deprecated#deprecated', via: :all
resources :maps, only: [:create, :show, :update, :destroy]
resources :synapses, only: [:create, :show, :update, :destroy]
resources :topics, only: [:create, :show, :update, :destroy]
resources :mappings, only: [:create, :show, :update, :destroy]
resources :tokens, only: [:create, :destroy] do
get :my_tokens, on: :collection
end
end end
match '*path', to: 'v2/restful#catch_404', via: :all
end end
devise_for :users, skip: :sessions, controllers: { devise_for :users, skip: :sessions, controllers: {