(dirs, renderFiles, lolwuts)
| 75 | res.setHeader('cache-control', cache); |
| 76 | |
| 77 | function render(dirs, renderFiles, lolwuts) { |
| 78 | // each entry in the array is a [name, stat] tuple |
| 79 | |
| 80 | let html = `${[ |
| 81 | '<!doctype html>', |
| 82 | '<html>', |
| 83 | ' <head>', |
| 84 | ' <meta charset="utf-8">', |
| 85 | ' <meta name="viewport" content="width=device-width">', |
| 86 | ` <title>Index of ${he.encode(pathname)}</title>`, |
| 87 | ` <style type="text/css">${css}</style>`, |
| 88 | ' </head>', |
| 89 | ' <body>', |
| 90 | `<h1>Index of ${he.encode(pathname)}</h1>`, |
| 91 | ].join('\n')}\n`; |
| 92 | |
| 93 | html += '<table>'; |
| 94 | |
| 95 | const failed = false; |
| 96 | const writeRow = (file) => { |
| 97 | // render a row given a [name, stat] tuple |
| 98 | const isDir = file[1].isDirectory && file[1].isDirectory(); |
| 99 | let href = `./${encodeURIComponent(file[0])}`; |
| 100 | |
| 101 | // append trailing slash and query for dir entry |
| 102 | if (isDir) { |
| 103 | href += `/${he.encode((parsed.search) ? parsed.search : '')}`; |
| 104 | } |
| 105 | |
| 106 | const displayName = he.encode(file[0]) + ((isDir) ? '/' : ''); |
| 107 | const ext = file[0].split('.').pop(); |
| 108 | const classForNonDir = supportedIcons[ext] ? ext : '_page'; |
| 109 | const iconClass = `icon-${isDir ? '_blank' : classForNonDir}`; |
| 110 | |
| 111 | // TODO: use stylessheets? |
| 112 | html += `${'<tr>' + |
| 113 | '<td><i class="icon '}${iconClass}"></i></td>`; |
| 114 | if (!hidePermissions) { |
| 115 | html += `<td class="perms"><code>(${permsToString(file[1])})</code></td>`; |
| 116 | } |
| 117 | html += |
| 118 | `<td class="last-modified">${lastModifiedToString(file[1])}</td>` + |
| 119 | `<td class="file-size"><code>${sizeToString(file[1], humanReadable, si)}</code></td>` + |
| 120 | `<td class="display-name"><a href="${href}">${displayName}</a></td>` + |
| 121 | '</tr>\n'; |
| 122 | }; |
| 123 | |
| 124 | dirs.sort((a, b) => a[0].toString().localeCompare(b[0].toString())).forEach(writeRow); |
| 125 | renderFiles.sort((a, b) => a.toString().localeCompare(b.toString())).forEach(writeRow); |
| 126 | lolwuts.sort((a, b) => a[0].toString().localeCompare(b[0].toString())).forEach(writeRow); |
| 127 | |
| 128 | html += '</table>\n'; |
| 129 | html += `<br><address>Node.js ${ |
| 130 | process.version |
| 131 | }/ <a href="https://github.com/http-party/http-server">http-server</a> ` + |
| 132 | `server running @ ${ |
| 133 | he.encode(req.headers.host || '')}</address>\n` + |
| 134 | '</body></html>' |
no outgoing calls
no test coverage detected
searching dependent graphs…