Skip to content
Closed
Show file tree
Hide file tree
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
5 changes: 5 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,11 @@ all methods.

The default value is `true`.

##### followSymlinks

Enable or disable following symbolic links, defaults to `true`. Set to `false`
to restrict symlink traversal outside root.

##### immutable

Enable or disable the `immutable` directive in the `Cache-Control` response
Expand Down
3 changes: 3 additions & 0 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,9 @@ function serveStatic (root, options) {
}

// setup options for send
opts.followSymlinks = opts.followSymlinks !== undefined
? opts.followSymlinks
: true
opts.maxage = opts.maxage || opts.maxAge || 0
opts.root = resolve(root)

Expand Down
24 changes: 24 additions & 0 deletions test/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -398,6 +398,30 @@ describe('serveStatic()', function () {
})
})

describe('followSymlinks', function () {
it('should default to true', function (done) {
request(createServer(fixtures))
.get('/todo.txt')
.expect(200, '- groceries', done)
})

describe('when false', function () {
it('should accept followSymlinks: false', function (done) {
request(createServer(fixtures, { followSymlinks: false }))
.get('/todo.txt')
.expect(200, '- groceries', done)
})
})

describe('when true', function () {
it('should accept followSymlinks: true', function (done) {
request(createServer(fixtures, { followSymlinks: true }))
.get('/todo.txt')
.expect(200, '- groceries', done)
})
})
})

describe('hidden files', function () {
var server
before(function () {
Expand Down