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 V1
class DeprecatedController < ApplicationController
# rubocop:disable Style/MethodMissing
def method_missing
render json: { error: '/api/v1 is deprecated! Please use /api/v2 instead.' }
def deprecated
render json: {
error: '/api/v1 has been deprecated! Please use /api/v2 instead.'
}, status: :gone
end
# rubocop:enable Style/MethodMissing
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
end
def catch_404
skip_authorization
render json: { error: '404 Not found' }, status: :not_found
end
private
def accessible_records

View file

@ -77,18 +77,13 @@ Metamaps::Application.routes.draw do
resources :users, only: [:index, :show] do
get :current, on: :collection
end
match '*path', to: 'restful#catch_404', via: :all
end
namespace :v1, path: '/v1' do
# api v1 routes all lead to a deprecation error method
# see app/controllers/api/v1/deprecated_controller.rb
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
root to: 'deprecated#deprecated', via: :all
match '*path', to: 'deprecated#deprecated', via: :all
end
match '*path', to: 'v2/restful#catch_404', via: :all
end
devise_for :users, skip: :sessions, controllers: {