({ path, hostname })
| 69 | |
| 70 | // Maps a given server file to a URL |
| 71 | async mapFileToUrl ({ path, hostname }) { |
| 72 | // Remove the root path if specified |
| 73 | path = path.replace(/\\/g, '/') |
| 74 | if (path.startsWith(this._rootPath)) { |
| 75 | path = path.substring(this._rootPath.length) |
| 76 | } |
| 77 | if (this._includeHost) { |
| 78 | if (!path.startsWith(`/${hostname}/`)) { |
| 79 | throw new Error(`Path must start with hostname (/${hostname})`) |
| 80 | } |
| 81 | path = path.substring(hostname.length + 1) |
| 82 | } |
| 83 | |
| 84 | // Determine the URL by chopping off everything after the dollar sign |
| 85 | const pathname = this._removeDollarExtension(path) |
| 86 | const url = `${this.resolveUrl(hostname)}${this._encodePath(pathname)}` |
| 87 | return { url, contentType: this._getContentTypeFromExtension(path) } |
| 88 | } |
| 89 | |
| 90 | // Maps the request for a given resource and representation format to a server file |
| 91 | // Will look for an index file if a folder is given and searchIndex is true |
no test coverage detected