Repository is archived
No commit activity in last 3 years
No release in over 3 years
If you're running a javascript single-page-app with html5 routing, you may notice that deep links will 404 unless your web front-end is configured to rewrite all non-asset paths to index.html. If you'd like to achieve the same rewrite using rack, this is the gem for you!
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
 Dependencies

Development

~> 1.10
~> 5.6
~> 10.0

Runtime

 Project Readme

Rack Single Page App Middleware

This middleware for Rack will route all web requests to a single file and return a '200' status code.

The intention is to allow rack-based application servers to run single-page webapps which use HTML5 routing, a common pattern which is normally handled by the front-end web server.

If you are unable or unwilling to reconfigure your web server, this gem may provide what you require!

Installation

Install the gem:

gem install rack-single-page-app

Or in your Gemfile:

gem 'rack-single-page-app', :require => 'rack/single_page_app'

Configuration

Static Index Page

In config.ru, configure Rack::SinglePageApp::Index by passing the destination file to the constructor:

run Rack::SinglePageApp::Index.new("public/index.html")

Generally, you'll run Rack::Static higher up in your config.ru so that you deliver static assets prior to single-page-app fall-through.

Mustache Templates

Use Rack::SinglePageApp::Template to compile the static output from a Mustache template. Pass the path to the template and a context object to the constructor:

run Rack::SinglePageApp::Index.new("templates/index.html", context)

Note that this template will be compiled once in-memory when the app starts up, and the content will be static for the lifetime of the app.

Testing

To contribute to the project, begin by cloning the repo and installing the necessary gems:

gem install json rack ruby-prof test-spec test-unit

To run the entire test suite, run

rake test