annotate piecrust/resources/server/piecrust-debug-info.js @ 380:f33712c4cfab

routing: Fix bugs with matching URLs with correct route but missing metadata. When matching a route like `/foo/%slug%` against an URL like `/foo`, the route will (correctly) return a match, but it will be completely missing the `slug` metadata, resulting in problems elsewhere. This change makes it so that any missing route metadata will be filled in with an empty string. And because this means generated URLs may differ from the incoming URL when using trailing slashes (`/foo/` _vs._ `/foo`), we make the assert in the chef server handle those discrepancies.
author Ludovic Chabant <ludovic@chabant.com>
date Sun, 10 May 2015 00:34:21 -0700
parents d7a548ebcd58
children 9612cfc6455a
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
219
d7a548ebcd58 serve: Add server sent events for showing pipeline errors in the debug window.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
1 var eventSource = new EventSource("/__piecrust_debug/pipeline_status");
d7a548ebcd58 serve: Add server sent events for showing pipeline errors in the debug window.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
2
d7a548ebcd58 serve: Add server sent events for showing pipeline errors in the debug window.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
3 //window.onbeforeunload = function(e) {
d7a548ebcd58 serve: Add server sent events for showing pipeline errors in the debug window.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
4 // console.log("Disconnecting SSE.", e);
d7a548ebcd58 serve: Add server sent events for showing pipeline errors in the debug window.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
5 // eventSource.close();
d7a548ebcd58 serve: Add server sent events for showing pipeline errors in the debug window.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
6 //};
d7a548ebcd58 serve: Add server sent events for showing pipeline errors in the debug window.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
7
d7a548ebcd58 serve: Add server sent events for showing pipeline errors in the debug window.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
8 eventSource.onerror = function(e) {
d7a548ebcd58 serve: Add server sent events for showing pipeline errors in the debug window.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
9 console.log("Error with SSE, closing.", e);
d7a548ebcd58 serve: Add server sent events for showing pipeline errors in the debug window.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
10 eventSource.close();
d7a548ebcd58 serve: Add server sent events for showing pipeline errors in the debug window.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
11 };
d7a548ebcd58 serve: Add server sent events for showing pipeline errors in the debug window.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
12
d7a548ebcd58 serve: Add server sent events for showing pipeline errors in the debug window.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
13 eventSource.addEventListener('pipeline_success', function(e) {
d7a548ebcd58 serve: Add server sent events for showing pipeline errors in the debug window.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
14 var placeholder = document.getElementById('piecrust-debug-info-pipeline-status');
d7a548ebcd58 serve: Add server sent events for showing pipeline errors in the debug window.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
15 //if (placeholder.firstChild !== null)
d7a548ebcd58 serve: Add server sent events for showing pipeline errors in the debug window.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
16 placeholder.removeChild(placeholder.firstChild);
d7a548ebcd58 serve: Add server sent events for showing pipeline errors in the debug window.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
17 });
d7a548ebcd58 serve: Add server sent events for showing pipeline errors in the debug window.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
18
d7a548ebcd58 serve: Add server sent events for showing pipeline errors in the debug window.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
19 eventSource.addEventListener('pipeline_error', function(e) {
d7a548ebcd58 serve: Add server sent events for showing pipeline errors in the debug window.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
20 var obj = JSON.parse(e.data);
d7a548ebcd58 serve: Add server sent events for showing pipeline errors in the debug window.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
21
d7a548ebcd58 serve: Add server sent events for showing pipeline errors in the debug window.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
22 var outer = document.createElement('div');
d7a548ebcd58 serve: Add server sent events for showing pipeline errors in the debug window.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
23 outer.style = 'padding: 1em;';
d7a548ebcd58 serve: Add server sent events for showing pipeline errors in the debug window.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
24 for (var i = 0; i < obj.assets.length; ++i) {
d7a548ebcd58 serve: Add server sent events for showing pipeline errors in the debug window.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
25 var item = obj.assets[i];
d7a548ebcd58 serve: Add server sent events for showing pipeline errors in the debug window.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
26 var markup = (
d7a548ebcd58 serve: Add server sent events for showing pipeline errors in the debug window.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
27 '<p>Error processing: <span style="font-family: monospace;">' +
d7a548ebcd58 serve: Add server sent events for showing pipeline errors in the debug window.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
28 item.path + '</span></p>\n' +
d7a548ebcd58 serve: Add server sent events for showing pipeline errors in the debug window.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
29 '<ul>');
d7a548ebcd58 serve: Add server sent events for showing pipeline errors in the debug window.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
30 for (var j = 0; j < item.errors.length; ++j) {
d7a548ebcd58 serve: Add server sent events for showing pipeline errors in the debug window.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
31 markup += (
d7a548ebcd58 serve: Add server sent events for showing pipeline errors in the debug window.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
32 '<li style="font-family: monospace;">' +
d7a548ebcd58 serve: Add server sent events for showing pipeline errors in the debug window.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
33 item.errors[j] +
d7a548ebcd58 serve: Add server sent events for showing pipeline errors in the debug window.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
34 '</li>\n');
d7a548ebcd58 serve: Add server sent events for showing pipeline errors in the debug window.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
35 }
d7a548ebcd58 serve: Add server sent events for showing pipeline errors in the debug window.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
36 markup += '</ul>\n';
d7a548ebcd58 serve: Add server sent events for showing pipeline errors in the debug window.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
37 var entry = document.createElement('div');
d7a548ebcd58 serve: Add server sent events for showing pipeline errors in the debug window.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
38 entry.innerHTML = markup;
d7a548ebcd58 serve: Add server sent events for showing pipeline errors in the debug window.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
39 outer.appendChild(entry);
d7a548ebcd58 serve: Add server sent events for showing pipeline errors in the debug window.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
40 }
d7a548ebcd58 serve: Add server sent events for showing pipeline errors in the debug window.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
41
d7a548ebcd58 serve: Add server sent events for showing pipeline errors in the debug window.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
42 var placeholder = document.getElementById('piecrust-debug-info-pipeline-status');
d7a548ebcd58 serve: Add server sent events for showing pipeline errors in the debug window.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
43 placeholder.appendChild(outer);
d7a548ebcd58 serve: Add server sent events for showing pipeline errors in the debug window.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
44 });
d7a548ebcd58 serve: Add server sent events for showing pipeline errors in the debug window.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
45