MCPcopy Index your code
hub / github.com/nodeSolidServer/node-solid-server / handler

Function handler

lib/handlers/index.mjs:8–39  ·  view source on GitHub ↗
(req, res, next)

Source from the content-addressed store, hash-verified

6const debug = debugModule('solid:index')
7
8export 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}

Callers

nothing calls this directly

Calls 3

mapUrlToFileMethod · 0.80
statMethod · 0.80
existsMethod · 0.80

Tested by

no test coverage detected