Skip to content

Commit

Permalink
Fixes #60
Browse files Browse the repository at this point in the history
  • Loading branch information
zachleat committed Jun 4, 2024
1 parent 250f1de commit 5ea1b54
Showing 1 changed file with 6 additions and 3 deletions.
9 changes: 6 additions & 3 deletions server.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ const DEFAULT_OPTIONS = {
watch: [], // Globs to pass to separate dev server chokidar for watching
aliases: {}, // Aliasing feature
indexFileName: "index.html", // Allow custom index file name
useCache: false, // Use a cache for file contents

onRequest: {}, // Maps URLPatterns to dynamic callback functions that run on a request from a client.

Expand Down Expand Up @@ -315,8 +316,8 @@ class EleventyDevServer {
};
}

_getFileContents(localpath, rootDir, useCache = true) {
if(this.fileCache[localpath]) {
_getFileContents(localpath, rootDir) {
if(this.options.useCache && this.fileCache[localpath]) {
return this.fileCache[localpath];
}

Expand All @@ -326,6 +327,7 @@ class EleventyDevServer {
if(rootDir) {
searchLocations.push(TemplatePath.absolutePath(rootDir, localpath));
}

// fallbacks for file:../ installations
searchLocations.push(TemplatePath.absolutePath(__dirname, localpath));
searchLocations.push(TemplatePath.absolutePath(__dirname, "../../../", localpath));
Expand All @@ -340,7 +342,8 @@ class EleventyDevServer {
let contents = fs.readFileSync(filepath, {
encoding: this.options.encoding,
});
if(useCache) {

if(this.options.useCache) {
this.fileCache[localpath] = contents;
}
return contents;
Expand Down

0 comments on commit 5ea1b54

Please sign in to comment.