OLD | NEW |
1 >>> | 1 >>> |
2 return environment.barback.getAssetById(id).then((result) { | 2 return environment.barback.getAssetById(id).then((result) { |
3 return result; | 3 return result; |
4 }).then((asset) => _serveAsset(request, asset)).catchError( | 4 }).then((asset) => _serveAsset(request, asset)).catchError( |
5 (error, | 5 (error, |
6 trace) { | 6 trace) { |
7 if (error is! AssetNotFoundException) throw error; | 7 if (error is! AssetNotFoundException) throw error; |
8 return environment.barback | 8 return environment.barback |
9 .getAssetById(id.addExtension("/index.html")) | 9 .getAssetById(id.addExtension("/index.html")) |
10 .then((asset) { | 10 .then((asset) { |
(...skipping 18 matching lines...) Expand all Loading... |
29 | 29 |
30 addError(error, trace); | 30 addError(error, trace); |
31 close(); | 31 close(); |
32 return new shelf.Response.internalServerError(); | 32 return new shelf.Response.internalServerError(); |
33 } | 33 } |
34 | 34 |
35 addResult(new BarbackServerResult._failure(request.url, id, error)); | 35 addResult(new BarbackServerResult._failure(request.url, id, error)); |
36 return notFound(request, asset: id); | 36 return notFound(request, asset: id); |
37 }); | 37 }); |
38 <<< | 38 <<< |
39 return environment.barback.getAssetById(id).then((result) { | 39 return environment.barback |
40 return result; | 40 .getAssetById(id) |
41 }).then((asset) => _serveAsset(request, asset)).catchError((error, trace) { | 41 .then((result) { |
42 if (error is! AssetNotFoundException) throw error; | 42 return result; |
43 return environment.barback | 43 }) |
44 .getAssetById(id.addExtension("/index.html")) | 44 .then((asset) => _serveAsset(request, asset)) |
45 .then((asset) { | 45 .catchError((error, trace) { |
46 if (request.url.path.endsWith('/')) return _serveAsset(request, asset); | 46 if (error is! AssetNotFoundException) throw error; |
| 47 return environment.barback |
| 48 .getAssetById(id.addExtension("/index.html")) |
| 49 .then((asset) { |
| 50 if (request.url.path.endsWith('/')) return _serveAsset(request, asset); |
47 | 51 |
48 // We only want to serve index.html if the URL explicitly ends in a | 52 // We only want to serve index.html if the URL explicitly ends in a |
49 // slash. For other URLs, we redirect to one with the slash added to | 53 // slash. For other URLs, we redirect to one with the slash added to |
50 // implicitly support that too. This follows Apache's behavior. | 54 // implicitly support that too. This follows Apache's behavior. |
51 logRequest(request, "302 Redirect to ${request.url}/"); | 55 logRequest(request, "302 Redirect to ${request.url}/"); |
52 return new shelf.Response.found('${request.url}/'); | 56 return new shelf.Response.found('${request.url}/'); |
53 }).catchError((newError, newTrace) { | 57 }).catchError((newError, newTrace) { |
54 // If we find neither the original file or the index, we should report | 58 // If we find neither the original file or the index, we should report |
55 // the error about the original to the user. | 59 // the error about the original to the user. |
56 throw newError is AssetNotFoundException ? error : newError; | 60 throw newError is AssetNotFoundException ? error : newError; |
57 }); | 61 }); |
58 }).catchError((error, trace) { | 62 }) |
59 if (error is! AssetNotFoundException) { | 63 .catchError((error, trace) { |
60 trace = new Chain.forTrace(trace); | 64 if (error is! AssetNotFoundException) { |
61 logRequest(request, "$error\n$trace"); | 65 trace = new Chain.forTrace(trace); |
| 66 logRequest(request, "$error\n$trace"); |
62 | 67 |
63 addError(error, trace); | 68 addError(error, trace); |
64 close(); | 69 close(); |
65 return new shelf.Response.internalServerError(); | 70 return new shelf.Response.internalServerError(); |
66 } | 71 } |
67 | 72 |
68 addResult(new BarbackServerResult._failure(request.url, id, error)); | 73 addResult(new BarbackServerResult._failure(request.url, id, error)); |
69 return notFound(request, asset: id); | 74 return notFound(request, asset: id); |
70 }); | 75 }); |
OLD | NEW |