From 13f92de6246a0af8450fde84b209211a56397fda Mon Sep 17 00:00:00 2001 From: Vojta Jina Date: Tue, 30 Aug 2011 11:47:24 +0200 Subject: feat(docs): use html5 history api for all routing in the docs app - Configure our docs app to use new $location with html5 history api! - Update simple node web server to serve index.html for all links (rewritting). - Update .htaccess file to serve index.html for all links (rewritting). - At runtime determine the base href path and attach it to the DOM. We needed the absolute URL to get all browsers to work well. - Because of the above, we also need to dynamically determine all needed js/css resources and add them to the DOM. This was needed because FF6 would eagerly fetch resources with wrong URL since the base element is added to the dom at runtime. - All content html files were moved to the partials directory, because with the new html5 urls it was impossible to tell if request for http://domain/api/angular.filter.html was an html5 url for the html filter doc page, or an xhr/appcache request for the content html file for the html filter. f --- lib/nodeserver/server.js | 12 ++++++++++++ 1 file changed, 12 insertions(+) (limited to 'lib') diff --git a/lib/nodeserver/server.js b/lib/nodeserver/server.js index 471bba94..54ae78fc 100644 --- a/lib/nodeserver/server.js +++ b/lib/nodeserver/server.js @@ -91,6 +91,18 @@ StaticServlet.prototype.handleRequest = function(req, res) { var parts = path.split('/'); if (parts[parts.length-1].charAt(0) === '.') return self.sendForbidden_(req, res, path); + + // docs rewriting + var REWRITE = /\/(guide|api|cookbook|misc|tutorial)\/.*$/, + IGNORED = /(\.(css|js|png|jpg)$|partials\/.*\.html$)/, + match; + + if (!IGNORED.test(path) && (match = path.match(REWRITE))) { + path = path.replace(match[0], '/index.html'); + sys.puts('Rewrite to ' + path); + } + // end of docs rewriting + fs.stat(path, function(err, stat) { if (err) return self.sendMissing_(req, res, path); -- cgit v1.2.3