Skip to content

Commit

Permalink
replace fs sync with async yield (#167)
Browse files Browse the repository at this point in the history
  • Loading branch information
JamesKyburz authored and leo committed Apr 19, 2017
1 parent 5967c22 commit f12e888
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions lib/server.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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)
Expand All @@ -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(
Expand Down Expand Up @@ -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)
}
Expand Down

0 comments on commit f12e888

Please sign in to comment.