From 64731e92f729f8027f797196650eb75412ec9a6e Mon Sep 17 00:00:00 2001 From: James Kyburz Date: Wed, 19 Apr 2017 10:01:20 +0200 Subject: [PATCH] replace fs sync with async yield --- lib/server.js | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/lib/server.js b/lib/server.js index d10b5500..b1a484a2 100644 --- a/lib/server.js +++ b/lib/server.js @@ -69,7 +69,7 @@ module.exports = coroutine(function*(req, res, flags, current, ignoredFiles) { related = decodeURIComponent(path.format(related)) - const relatedExists = fs.existsSync(related) + const relatedExists = yield fs.exists(related) let notFoundResponse = 'Not Found' try { @@ -88,7 +88,7 @@ module.exports = coroutine(function*(req, res, flags, current, ignoredFiles) { } // Check if directory - if (relatedExists && pathType.dirSync(related)) { + if (relatedExists && (yield pathType.dir(related))) { // Normalize path to trailing slash // Otherwise problems like #70 will occur const url = parse(req.url) @@ -108,7 +108,7 @@ module.exports = coroutine(function*(req, res, flags, current, ignoredFiles) { let indexPath = path.join(related, '/index.html') res.setHeader('Content-Type', mime.contentType(path.extname(indexPath))) - if (!fs.existsSync(indexPath)) { + if (!(yield fs.exists(indexPath))) { // Try to render the current directory's content const port = flags.port || req.socket.localPort const renderedDir = yield renderDirectory( @@ -136,7 +136,7 @@ module.exports = coroutine(function*(req, res, flags, current, ignoredFiles) { return stream(req, indexPath, streamOptions).pipe(res) } - if (!fs.existsSync(related) && flags.single) { + if (!(yield fs.exists(related)) && flags.single) { const indexPath = path.join(current, '/index.html') return stream(req, indexPath, streamOptions).pipe(res) }