Eliminate unnecessary file read
This commit is contained in:
parent
a485858381
commit
f54b56b090
|
@ -64,21 +64,10 @@ function findFile(req, res, next) {
|
|||
} else {
|
||||
// No filename in the URL. Try to figure out which file they want by
|
||||
// checking package.json's "unpkg", "browser", and "main" fields.
|
||||
fs.readFile(path.join(req.packageDir, 'package.json'), 'utf8', function (error, data) {
|
||||
if (error) {
|
||||
console.error(error)
|
||||
return res.status(500).send(`Cannot read ${req.packageSpec}/package.json`)
|
||||
}
|
||||
|
||||
let packageConfig
|
||||
try {
|
||||
packageConfig = JSON.parse(data)
|
||||
} catch (error) {
|
||||
return res.status(500).send(`Cannot parse ${req.packageSpec}/package.json: ${error.message}`)
|
||||
}
|
||||
|
||||
let mainFilename
|
||||
const queryMain = query && query.main
|
||||
|
||||
const packageConfig = req.packageConfig
|
||||
const queryMain = req.query.main
|
||||
|
||||
if (queryMain) {
|
||||
if (!(queryMain in packageConfig))
|
||||
|
@ -111,7 +100,6 @@ function findFile(req, res, next) {
|
|||
next()
|
||||
}
|
||||
})
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue