-
Notifications
You must be signed in to change notification settings - Fork 100
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add support for multiple root directories under a single prefix (…
…#169) * feat: add support for multiple root directories under a single prefix * revert: undo test changes to the server example * wip: support glob paths when using multiple root path array * feat: add support for glob filenames on multiple root paths * chore: add missing newline and additional note to readme. * tests: add back in tests that got moved or removed during dev * fix: change async for util.promisify and update glob function * fix: switch to async/await and use promises for glob routes * chore: move promisify glob to top of file * Update README.md Co-authored-by: Simone Busoli <simone.busoli@gmail.com> * fix: cleanups and extra docs on examples Co-authored-by: Simone Busoli <simone.busoli@gmail.com>
- Loading branch information
1 parent
756b95d
commit 38638bc
Showing
13 changed files
with
407 additions
and
136 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
body { | ||
background-color: black; | ||
color: white; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
<html> | ||
<head> | ||
<link rel="stylesheet" type="text/css" href="test.css"></link> | ||
</head> | ||
<body> | ||
<h1>Test 2</h1> | ||
</body> | ||
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
'use strict' | ||
|
||
const path = require('path') | ||
const Handlebars = require('handlebars') | ||
|
||
const fastify = require('fastify')({ logger: { level: 'trace' } }) | ||
|
||
// Handlebar template for listing files and directories. | ||
const template = ` | ||
<html> | ||
<body> | ||
dirs | ||
<ul> | ||
{{#dirs}} | ||
<li><a href="{{href}}">{{name}}</a></li> | ||
{{/dirs}} | ||
</ul> | ||
list | ||
<ul> | ||
{{#files}} | ||
<li><a href="{{href}}" target="_blank">{{name}}</a></li> | ||
{{/files}} | ||
</ul> | ||
</body> | ||
</html> | ||
` | ||
const handlebarTemplate = Handlebars.compile(template) | ||
|
||
fastify | ||
.register(require('..'), { | ||
// Array of absolute paths containing static files to serve | ||
root: [path.join(__dirname, '/public'), path.join(__dirname, '/public2')], | ||
// Do not append a trailing slash to prefixes | ||
prefixAvoidTrailingSlash: true, | ||
// Return a directory listing with a handlebar template | ||
list: { | ||
// html or json response? html requires a render method. | ||
format: 'html', | ||
// A list of filenames that trigger a directory list response. | ||
names: ['index', 'index.html', 'index.htm', '/'], | ||
// You can provide your own render method as needed. | ||
render: (dirs, files) => handlebarTemplate({ dirs, files }) | ||
} | ||
}) | ||
.listen(3000, err => { | ||
if (err) throw err | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.