I'd like certain rails routes to only be accessible from localhost. In other words if you attempted to access that url from a non localhost connection you would be given a response equivalent to the route not existing.
Optimally some way of specifying routes as local in the routes.rb itself would be the cleanest solution but if there is some way to filter the request later at the controller level for example thats okay too.
If you want to specify that these urls exist only in a development environment, you can do just simple:
if Rails.env.development?
#your routes
end
But if your server in development mode is being accessed by others and you want to specify that these routes exist for localhost only then you can add constraint for domain:
if Rails.env.development?
resources :users, constraints: { domain: 'localhost' }
end
The file routes.rb
contains special DSL for routes, but it's still ruby.
So, did you try put your routes in simple condition?
# routes.rb
if Rails.env.development?
# your special local routes definition
end
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With