Skip to content
This repository has been archived by the owner on Feb 12, 2024. It is now read-only.

fix(gateway): keep pretty URL and return implicit index.html #2217

Merged
merged 1 commit into from
Jul 5, 2019

Conversation

lidel
Copy link
Member

@lidel lidel commented Jul 4, 2019

This cosmetic PR enables pretty URLs for directories with index.html
It follows what go-ipfs does: return implicit index.html without changing URL

TL;DR:

It also makes logs more useful by showing both requested HTTP path and resolved IPFS one:

ipfs:http-gateway HTTP path  /ipns/tr.wikipedia-on-ipfs.org/ +0ms
ipfs:http-gateway IPFS path  /ipfs/QmT5NvUtoM5nWFfrQdVrFtvGfKFmG7AHE8P34isapyhCxX/index.html +0ms

This changes current logic (redirect to index.html) to match what
go-ipfs does (return index.html without changing URL)

We also ensure directory URLs always end with '/'

License: MIT
Signed-off-by: Marcin Rataj <lidel@lidel.org>
@lidel lidel requested a review from alanshaw July 4, 2019 21:08
? await ipfs.name.resolve(path, { recursive: true })
: path)

let directory = false
Copy link
Member Author

@lidel lidel Jul 4, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I went with explicit flag to make it easier to review/modify code paths related to directories (with and without index.html)

@@ -153,7 +159,7 @@ module.exports = {
log.error(err)
return reject(err)
}
resolve({ peekedStream, contentType: detectContentType(path, streamHead) })
resolve({ peekedStream, contentType: detectContentType(ipfsPath, streamHead) })
Copy link
Member Author

@lidel lidel Jul 4, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ipfsPath instead of path because if we are returning implicit index.html we want to detect HTML content type of the file, not the dir.

@lidel lidel mentioned this pull request Jul 4, 2019
54 tasks
Copy link
Member

@alanshaw alanshaw left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, thanks @lidel

@alanshaw alanshaw merged commit 8519886 into master Jul 5, 2019
@alanshaw alanshaw deleted the fix/gateway-directories-with-index branch July 5, 2019 12:49
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants