File tree Expand file tree Collapse file tree 5 files changed +16
-18
lines changed Expand file tree Collapse file tree 5 files changed +16
-18
lines changed Original file line number Diff line number Diff line change @@ -71,8 +71,9 @@ fs.readFile('/test/file.txt').then((contents) => {
71
71
72
72
### Options
73
73
74
- - ` endpoint ` : Address endpoint of server
75
- - ` maxAge ` : Time to keep requests in cache
74
+ #### ` endpoint `
75
+
76
+ Required. HTTP URL of server.
76
77
77
78
## License
78
79
Original file line number Diff line number Diff line change 1
1
const fetch = require ( 'node-fetch' )
2
- const pMemoize = require ( 'p-memoize' )
3
2
4
3
module . exports = class HTTPFSClient {
5
- constructor ( { endpoint, maxAge = 1000 } ) {
6
- this . endpoint = endpoint . replace ( / \/ $ / , '' )
7
- this . _request = pMemoize ( this . _request , { maxAge } )
4
+ constructor ( options = { } ) {
5
+ if ( ! options . endpoint ) {
6
+ throw new Error ( 'Missing required option `endpoint`' )
7
+ }
8
+ this . endpoint = options . endpoint . replace ( / \/ $ / , '' )
8
9
}
9
10
10
11
_url ( path ) {
@@ -18,11 +19,11 @@ module.exports = class HTTPFSClient {
18
19
}
19
20
20
21
async exists ( path ) {
21
- const res = await this . _request ( path )
22
+ const res = await this . _request ( path , { method : 'HEAD' } )
22
23
switch ( res . status ) {
23
24
case 200 : return true
24
25
case 404 : return false
25
- default : throw new Error ( 'Invalid status ' + res . status )
26
+ default : throw new Error ( 'Unexpected status ' + res . status )
26
27
}
27
28
}
28
29
Original file line number Diff line number Diff line change @@ -12,6 +12,11 @@ module.exports = function HTTPFSMiddleware (mfs) {
12
12
return res . end ( 'No such a file or directory: ' + resourcePath )
13
13
}
14
14
15
+ // End response for HEAD requests
16
+ if ( req . method === 'HEAD' ) {
17
+ return res . end ( )
18
+ }
19
+
15
20
// Directory listing
16
21
if ( stat . isDirectory ( ) ) {
17
22
return res . end ( `
Original file line number Diff line number Diff line change 33
33
},
34
34
"dependencies" : {
35
35
"errno" : " ^0.1.7" ,
36
- "node-fetch" : " ^2.3.0" ,
37
- "p-memoize" : " ^2.1.0"
36
+ "node-fetch" : " ^2.3.0"
38
37
}
39
38
}
Original file line number Diff line number Diff line change @@ -3633,14 +3633,6 @@ p-locate@^3.0.0:
3633
3633
dependencies :
3634
3634
p-limit "^2.0.0"
3635
3635
3636
- p-memoize@^2.1.0 :
3637
- version "2.1.0"
3638
- resolved "https://registry.yarnpkg.com/p-memoize/-/p-memoize-2.1.0.tgz#9ac80c8cf9373c52dfece6aae1fd2e300602898a"
3639
- integrity sha512-c6+a2iV4JyX0r4+i2IBJYO0r6LZAT2fg/tcB6GQbv1uzZsfsmKT7Ej5DRT1G6Wi7XUJSV2ZiP9+YEtluvhCmkg==
3640
- dependencies :
3641
- mem "^4.0.0"
3642
- mimic-fn "^1.0.0"
3643
-
3644
3636
p-reduce@^1.0.0 :
3645
3637
version "1.0.0"
3646
3638
resolved "https://registry.yarnpkg.com/p-reduce/-/p-reduce-1.0.0.tgz#18c2b0dd936a4690a529f8231f58a0fdb6a47dfa"
You can’t perform that action at this time.
0 commit comments