200 OK status code
Use Harp’s 200 file to route a client side app.
Why
If you’re writing a client-side application using a framework like Backbone, Angular, or Ember, you’ll want to do your routing client-side, using HTML5 PushState. The 200 file lets you provide a 200 OK
status code
Usage
Replace your 404 file with a 200.jade
, 200.ejs
or 200.md
file to get started. This file must be in the root directory of your application.
Example
Given the following directory strucutre:
myproject/
|- 200.ejs
|- app.js
|- framework.js
+- main.scss
The 200.ejs
file will be served after all static routes and just before a 404 is found, allowing you to do any routing on the client side.
This works great in conjunction with static pages. For example, if you had a client side app but wanted your blog to be static and not use the router, your application might look like this:
myproject/
|- _layout.ejs
|- 200.ejs
|- css/
+- main.scss
|- js/
|- app.js
+- framework.js
+- blog/
|- _data.json
|- index.ejs
|- my-post-1.md
+- my-post-2.md
Now, if you visit /blog
in the browser, the 200
file will still be served first. If your client side router doesn’t do anything with this request, your static blog will be served instead.
There are lots of client side routers and frameworks to play with: