Git Product home page Git Product logo

strong_routes's Introduction

Build Status

Strong Routes

Strong Routes is a simple Rack middleware to reject requests to unknown routes before allocating connections or any resources.

Installation

Add this line to your application's Gemfile:

gem 'strong_routes'

And then execute:

$ bundle

Or install it yourself as:

$ gem install strong_routes

Usage

Rails Apps

In Rails apps, using strong routes is as simple as adding it to your Gemfile. The middleware is automatically added to the middleware stack. Any routes defined by the application are automatically allowed by default.

Rack Apps

In Rack apps, load the StrongRoutes::Allow middleware into your middleware stack:

app.insert_before StrongRoutes::Allow, ResourceLoadingMiddleware

In (non-Rails) Rack apps, allowed routes are empty default. Allowed routes are specified using the allowed_routes config option:

StrongRoutes.config.allowed_routes = [ '/', '/posts' ]

Routes can be specified as strings or regular expressions:

StrongRoutes.config.allowed_routes = [ /\A\//i, /\A\/posts/i ]

Response

Any routes that aren't allowed will return a 404 by default:

[ 404, { "Content-Type" => "text/html", "Content-Length" => "18" }, [ "Resource Not Found" ] ]

The message that is returned can be specified using the message config option:

StrongRoutes.config.message = File.read(Rails.root.join('public/404.html'))

Contributing

  1. Fork it ( http://github.com//strong_routes/fork )
  2. Create your feature branch (git checkout -b my-new-feature)
  3. Commit your changes (git commit -am 'Add some feature')
  4. Push to the branch (git push origin my-new-feature)
  5. Create new Pull Request

strong_routes's People

Contributors

liveh2o avatar quixoten avatar

Stargazers

 avatar

Watchers

 avatar  avatar

strong_routes's Issues

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.