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
|
||||
# rubocop:disable Style/MethodMissing
|
||||
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
|
||||
# rubocop:enable Style/MethodMissing
|
||||
end
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -77,6 +77,7 @@ 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
|
||||
|
@ -88,7 +89,9 @@ Metamaps::Application.routes.draw do
|
|||
resources :tokens, only: [:create, :destroy] do
|
||||
get :my_tokens, on: :collection
|
||||
end
|
||||
match '*path', to: 'deprecated#method_missing', via: :all
|
||||
end
|
||||
match '*path', to: 'v2/restful#catch_404', via: :all
|
||||
end
|
||||
|
||||
devise_for :users, skip: :sessions, controllers: {
|
||||
|
|
Loading…
Reference in a new issue