Skip to content

Commit 1465553

Browse files
authored
Implement serving directories (#16)
1 parent de5bbaf commit 1465553

File tree

1 file changed

+14
-1
lines changed

1 file changed

+14
-1
lines changed

src/fs.ts

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,21 @@ export async function copyFiles (filesToServe: FileToServe[], destinationDirecto
2424
if (destinationFilePath.substr(0, destinationDirectory.length) !== destinationDirectory) {
2525
throw new Error(`File would be served outside of destination directory: ${sourcePath} => ${servingPath}`)
2626
}
27+
2728
mkdirp.sync(path.dirname(destinationFilePath))
28-
return copyFile(sourcePath, destinationFilePath)
29+
30+
if (fs.statSync(sourcePath).isDirectory()) {
31+
const directoryFiles = fs.readdirSync(sourcePath)
32+
await copyFiles(
33+
directoryFiles.map(file => ({
34+
servingPath: path.join(servingPath, file),
35+
sourcePath: path.join(sourcePath, file)
36+
})),
37+
destinationDirectory
38+
)
39+
} else {
40+
await copyFile(sourcePath, destinationFilePath)
41+
}
2942
}
3043
))
3144
}

0 commit comments

Comments
 (0)