Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

replace fs sync with async yield #167

Merged
merged 2 commits into from
Apr 19, 2017
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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