(req, res, next)
| 6 | const debug = debugModule('solid:index') |
| 7 | |
| 8 | export default async function handler (req, res, next) { |
| 9 | const indexFile = 'index.html' |
| 10 | const ldp = req.app.locals.ldp |
| 11 | const negotiator = new Negotiator(req) |
| 12 | const requestedType = negotiator.mediaType() |
| 13 | |
| 14 | try { |
| 15 | const { path: filename } = await ldp.resourceMapper.mapUrlToFile({ url: req }) |
| 16 | |
| 17 | const stats = await ldp.stat(filename) |
| 18 | if (!stats.isDirectory()) { |
| 19 | return next() |
| 20 | } |
| 21 | // redirect to the right container if missing trailing / |
| 22 | if (req.path.lastIndexOf('/') !== req.path.length - 1) { |
| 23 | return res.redirect(301, URI.joinPaths(req.path, '/').toString()) |
| 24 | } |
| 25 | |
| 26 | if (requestedType && requestedType.indexOf('text/html') !== 0) { |
| 27 | return next() |
| 28 | } |
| 29 | debug('Looking for index in ' + req.path) |
| 30 | |
| 31 | // Check if file exists in first place |
| 32 | await ldp.exists(req.hostname, path.join(req.path, indexFile)) |
| 33 | res.locals.path = url.resolve(req.path, indexFile) |
| 34 | debug('Found an index for current path') |
| 35 | } catch (e) { |
| 36 | // Ignore errors |
| 37 | } |
| 38 | next() |
| 39 | } |
nothing calls this directly
no test coverage detected