return 404s for all unmatched api routes
This commit is contained in:
parent
dc55bae243
commit
2c64b67abd
3 changed files with 9 additions and 1 deletions
|
@ -4,7 +4,7 @@ module Api
|
||||||
class DeprecatedController < ApplicationController
|
class DeprecatedController < ApplicationController
|
||||||
# rubocop:disable Style/MethodMissing
|
# rubocop:disable Style/MethodMissing
|
||||||
def method_missing
|
def method_missing
|
||||||
render json: { error: '/api/v1 is deprecated! Please use /api/v2 instead.' }
|
render json: { error: '/api/v1 is deprecated! Please use /api/v2 instead.' }, status: :gone
|
||||||
end
|
end
|
||||||
# rubocop:enable Style/MethodMissing
|
# rubocop:enable Style/MethodMissing
|
||||||
end
|
end
|
||||||
|
|
|
@ -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
|
||||||
|
|
|
@ -77,6 +77,7 @@ 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
|
# api v1 routes all lead to a deprecation error method
|
||||||
|
@ -88,7 +89,9 @@ Metamaps::Application.routes.draw do
|
||||||
resources :tokens, only: [:create, :destroy] do
|
resources :tokens, only: [:create, :destroy] do
|
||||||
get :my_tokens, on: :collection
|
get :my_tokens, on: :collection
|
||||||
end
|
end
|
||||||
|
match '*path', to: 'deprecated#method_missing', via: :all
|
||||||
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: {
|
||||||
|
|
Loading…
Reference in a new issue