fix(aio): map the empty url to the correct doc path

This commit is contained in:
Peter Bacon Darwin 2017-03-04 16:27:38 +00:00 committed by Igor Minar
parent dd50922747
commit 4abd6f333c
2 changed files with 7 additions and 3 deletions

View File

@ -121,12 +121,15 @@ describe('DocumentService', () => {
expect(latestDocument).toEqual(doc1);
subscription.unsubscribe();
});
});
describe('computeMap', () => {
it('should map the "empty" location to the correct document request', () => {
let latestDocument: DocumentContents;
const { service, backend } = getServices();
service.currentDocument.subscribe(doc => latestDocument = doc);
expect(backend.connectionsArray[0].request.url).toEqual(CONTENT_URL_PREFIX + 'index.json');
});
});
});

View File

@ -43,8 +43,8 @@ export class DocumentService {
.get(path)
.map(res => res.json())
.catch((error: Response) => {
if (error.status === 404 && url !== FILE_NOT_FOUND_DOC) {
this.logger.error(`Document file not found at '${url}'`);
if (error.status === 404 && path !== FILE_NOT_FOUND_DOC) {
this.logger.error(`Document file not found at '${path}'`);
// using `getDocument` means that we can fetch the 404 doc contents from the server and cache it
return this.getDocument(FILE_NOT_FOUND_DOC);
} else {
@ -57,6 +57,7 @@ export class DocumentService {
private computePath(url) {
url = url.startsWith('/') ? url : '/' + url;
url = url.endsWith('/') ? url + 'index' : url;
return 'content/docs' + url + '.json';
}
}