promptgraph-mcp 2.4.7 → 2.4.8
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +3 -6
- package/ann.js +23 -51
- package/api.js +200 -0
- package/config.js +7 -0
- package/db.js +20 -0
- package/embedder.js +10 -0
- package/github-import.js +102 -22
- package/indexer.js +45 -11
- package/marketplace.js +47 -5
- package/package.json +9 -3
- package/search.js +84 -20
- package/src/filter/hard-filter.js +2 -0
- package/src/filter/train.js +3 -1
- package/src/store/flat-store.js +61 -0
- package/src/store/hnsw-store.js +187 -0
- package/src/store/index.js +19 -0
- package/src/store/vector-store.js +9 -0
- package/validator.js +7 -1
- package/registry/training/bad/accepts-HISTORY.md +0 -250
- package/registry/training/bad/argparse-CHANGELOG.md +0 -185
- package/registry/training/bad/balanced-match-LICENSE.md +0 -23
- package/registry/training/bad/better-sqlite3-README.md +0 -99
- package/registry/training/bad/bindings-LICENSE.md +0 -22
- package/registry/training/bad/bl-LICENSE.md +0 -13
- package/registry/training/bad/body-parser-README.md +0 -494
- package/registry/training/bad/bytes-HISTORY.md +0 -97
- package/registry/training/bad/camelcase-README.md +0 -135
- package/registry/training/bad/chai-README.md +0 -162
- package/registry/training/bad/cli-progress-LICENSE.md +0 -24
- package/registry/training/bad/content-type-HISTORY.md +0 -29
- package/registry/training/bad/cookie-SECURITY.md +0 -25
- package/registry/training/bad/cookie-signature-HISTORY.md +0 -70
- package/registry/training/bad/cors-README.md +0 -277
- package/registry/training/bad/cross-spawn-README.md +0 -89
- package/registry/training/bad/deep-extend-CHANGELOG.md +0 -46
- package/registry/training/bad/depd-HISTORY.md +0 -103
- package/registry/training/bad/esprima-README.md +0 -46
- package/registry/training/bad/etag-HISTORY.md +0 -83
- package/registry/training/bad/expect-type-SECURITY.md +0 -14
- package/registry/training/bad/finalhandler-HISTORY.md +0 -239
- package/registry/training/bad/fresh-HISTORY.md +0 -80
- package/registry/training/bad/glob-LICENSE.md +0 -63
- package/registry/training/bad/hono-README.md +0 -85
- package/registry/training/bad/http-errors-HISTORY.md +0 -186
- package/registry/training/bad/jose-LICENSE.md +0 -21
- package/registry/training/bad/jose-README.md +0 -153
- package/registry/training/bad/js-yaml-README.md +0 -299
- package/registry/training/bad/json-schema-typed-LICENSE.md +0 -57
- package/registry/training/bad/json-stringify-safe-CHANGELOG.md +0 -14
- package/registry/training/bad/lru-cache-LICENSE.md +0 -55
- package/registry/training/bad/media-typer-HISTORY.md +0 -50
- package/registry/training/bad/minimatch-LICENSE.md +0 -55
- package/registry/training/bad/minimist-CHANGELOG.md +0 -298
- package/registry/training/bad/minimist-README.md +0 -121
- package/registry/training/bad/ms-LICENSE.md +0 -21
- package/registry/training/bad/negotiator-HISTORY.md +0 -114
- package/registry/training/bad/on-finished-HISTORY.md +0 -98
- package/registry/training/bad/pkce-challenge-CHANGELOG.md +0 -114
- package/registry/training/bad/postcss-README.md +0 -28
- package/registry/training/bad/prebuild-install-CHANGELOG.md +0 -131
- package/registry/training/bad/proxy-addr-HISTORY.md +0 -161
- package/registry/training/bad/qs-CHANGELOG.md +0 -822
- package/registry/training/bad/rc-README.md +0 -227
- package/registry/training/bad/readable-stream-CONTRIBUTING.md +0 -38
- package/registry/training/bad/router-HISTORY.md +0 -228
- package/registry/training/bad/semver-README.md +0 -680
- package/registry/training/bad/send-README.md +0 -317
- package/registry/training/bad/serve-static-README.md +0 -253
- package/registry/training/bad/statuses-HISTORY.md +0 -87
- package/registry/training/bad/type-is-HISTORY.md +0 -292
- package/registry/training/bad/vary-HISTORY.md +0 -39
- package/registry/training/bad/vite-LICENSE.md +0 -2230
- package/registry/training/bad/which-CHANGELOG.md +0 -166
- package/registry/training/bad/zod-README.md +0 -191
- package/registry/training/good/skills-store-autopilot.md +0 -85
- package/registry/training/good/skills-store-bot-builder.md +0 -70
- package/registry/training/good/skills-store-chain.md +0 -136
- package/registry/training/good/skills-store-evolve.md +0 -100
- package/registry/training/good/skills-store-game.md +0 -27
- package/registry/training/good/skills-store-hunt.md +0 -102
- package/registry/training/good/skills-store-intel.md +0 -56
- package/registry/training/good/skills-store-memory-gc.md +0 -58
- package/registry/training/good/skills-store-pcsort.md +0 -207
- package/registry/training/good/skills-store-pickup.md +0 -60
- package/registry/training/good/skills-store-recon.md +0 -141
- package/registry/training/good/skills-store-remember.md +0 -64
- package/registry/training/good/skills-store-report.md +0 -117
- package/registry/training/good/skills-store-router.md +0 -225
- package/registry/training/good/skills-store-search.md +0 -168
- package/registry/training/good/skills-store-surface.md +0 -53
- package/registry/training/good/skills-store-token-scan.md +0 -141
- package/registry/training/good/skills-store-triage.md +0 -97
- package/registry/training/good/skills-store-unity.md +0 -733
- package/registry/training/good/skills-store-validate.md +0 -135
- package/registry/training/good/skills-store-web3-audit.md +0 -217
|
@@ -1,317 +0,0 @@
|
|
|
1
|
-
# send
|
|
2
|
-
|
|
3
|
-
[![NPM Version][npm-version-image]][npm-url]
|
|
4
|
-
[![NPM Downloads][npm-downloads-image]][npm-url]
|
|
5
|
-
[![CI][github-actions-ci-image]][github-actions-ci-url]
|
|
6
|
-
[![Test Coverage][coveralls-image]][coveralls-url]
|
|
7
|
-
|
|
8
|
-
Send is a library for streaming files from the file system as a http response
|
|
9
|
-
supporting partial responses (Ranges), conditional-GET negotiation (If-Match,
|
|
10
|
-
If-Unmodified-Since, If-None-Match, If-Modified-Since), high test coverage,
|
|
11
|
-
and granular events which may be leveraged to take appropriate actions in your
|
|
12
|
-
application or framework.
|
|
13
|
-
|
|
14
|
-
Looking to serve up entire folders mapped to URLs? Try [serve-static](https://www.npmjs.org/package/serve-static).
|
|
15
|
-
|
|
16
|
-
## Installation
|
|
17
|
-
|
|
18
|
-
This is a [Node.js](https://nodejs.org/en/) module available through the
|
|
19
|
-
[npm registry](https://www.npmjs.com/). Installation is done using the
|
|
20
|
-
[`npm install` command](https://docs.npmjs.com/getting-started/installing-npm-packages-locally):
|
|
21
|
-
|
|
22
|
-
```bash
|
|
23
|
-
$ npm install send
|
|
24
|
-
```
|
|
25
|
-
|
|
26
|
-
## API
|
|
27
|
-
|
|
28
|
-
```js
|
|
29
|
-
var send = require('send')
|
|
30
|
-
```
|
|
31
|
-
|
|
32
|
-
### send(req, path, [options])
|
|
33
|
-
|
|
34
|
-
Create a new `SendStream` for the given path to send to a `res`. The `req` is
|
|
35
|
-
the Node.js HTTP request and the `path` is a urlencoded path to send (urlencoded,
|
|
36
|
-
not the actual file-system path).
|
|
37
|
-
|
|
38
|
-
#### Options
|
|
39
|
-
|
|
40
|
-
##### acceptRanges
|
|
41
|
-
|
|
42
|
-
Enable or disable accepting ranged requests, defaults to true.
|
|
43
|
-
Disabling this will not send `Accept-Ranges` and ignore the contents
|
|
44
|
-
of the `Range` request header.
|
|
45
|
-
|
|
46
|
-
##### cacheControl
|
|
47
|
-
|
|
48
|
-
Enable or disable setting `Cache-Control` response header, defaults to
|
|
49
|
-
true. Disabling this will ignore the `immutable` and `maxAge` options.
|
|
50
|
-
|
|
51
|
-
##### dotfiles
|
|
52
|
-
|
|
53
|
-
Set how "dotfiles" are treated when encountered. A dotfile is a file
|
|
54
|
-
or directory that begins with a dot ("."). Note this check is done on
|
|
55
|
-
the path itself without checking if the path actually exists on the
|
|
56
|
-
disk. If `root` is specified, only the dotfiles above the root are
|
|
57
|
-
checked (i.e. the root itself can be within a dotfile when set
|
|
58
|
-
to "deny").
|
|
59
|
-
|
|
60
|
-
- `'allow'` No special treatment for dotfiles.
|
|
61
|
-
- `'deny'` Send a 403 for any request for a dotfile.
|
|
62
|
-
- `'ignore'` Pretend like the dotfile does not exist and 404.
|
|
63
|
-
|
|
64
|
-
The default value is _similar_ to `'ignore'`, with the exception that
|
|
65
|
-
this default will not ignore the files within a directory that begins
|
|
66
|
-
with a dot, for backward-compatibility.
|
|
67
|
-
|
|
68
|
-
##### end
|
|
69
|
-
|
|
70
|
-
Byte offset at which the stream ends, defaults to the length of the file
|
|
71
|
-
minus 1. The end is inclusive in the stream, meaning `end: 3` will include
|
|
72
|
-
the 4th byte in the stream.
|
|
73
|
-
|
|
74
|
-
##### etag
|
|
75
|
-
|
|
76
|
-
Enable or disable etag generation, defaults to true.
|
|
77
|
-
|
|
78
|
-
##### extensions
|
|
79
|
-
|
|
80
|
-
If a given file doesn't exist, try appending one of the given extensions,
|
|
81
|
-
in the given order. By default, this is disabled (set to `false`). An
|
|
82
|
-
example value that will serve extension-less HTML files: `['html', 'htm']`.
|
|
83
|
-
This is skipped if the requested file already has an extension.
|
|
84
|
-
|
|
85
|
-
##### immutable
|
|
86
|
-
|
|
87
|
-
Enable or disable the `immutable` directive in the `Cache-Control` response
|
|
88
|
-
header, defaults to `false`. If set to `true`, the `maxAge` option should
|
|
89
|
-
also be specified to enable caching. The `immutable` directive will prevent
|
|
90
|
-
supported clients from making conditional requests during the life of the
|
|
91
|
-
`maxAge` option to check if the file has changed.
|
|
92
|
-
|
|
93
|
-
##### index
|
|
94
|
-
|
|
95
|
-
By default send supports "index.html" files, to disable this
|
|
96
|
-
set `false` or to supply a new index pass a string or an array
|
|
97
|
-
in preferred order.
|
|
98
|
-
|
|
99
|
-
##### lastModified
|
|
100
|
-
|
|
101
|
-
Enable or disable `Last-Modified` header, defaults to true. Uses the file
|
|
102
|
-
system's last modified value.
|
|
103
|
-
|
|
104
|
-
##### maxAge
|
|
105
|
-
|
|
106
|
-
Provide a max-age in milliseconds for http caching, defaults to 0.
|
|
107
|
-
This can also be a string accepted by the
|
|
108
|
-
[ms](https://www.npmjs.org/package/ms#readme) module.
|
|
109
|
-
|
|
110
|
-
##### root
|
|
111
|
-
|
|
112
|
-
Serve files relative to `path`.
|
|
113
|
-
|
|
114
|
-
##### start
|
|
115
|
-
|
|
116
|
-
Byte offset at which the stream starts, defaults to 0. The start is inclusive,
|
|
117
|
-
meaning `start: 2` will include the 3rd byte in the stream.
|
|
118
|
-
|
|
119
|
-
#### Events
|
|
120
|
-
|
|
121
|
-
The `SendStream` is an event emitter and will emit the following events:
|
|
122
|
-
|
|
123
|
-
- `error` an error occurred `(err)`
|
|
124
|
-
- `directory` a directory was requested `(res, path)`
|
|
125
|
-
- `file` a file was requested `(path, stat)`
|
|
126
|
-
- `headers` the headers are about to be set on a file `(res, path, stat)`
|
|
127
|
-
- `stream` file streaming has started `(stream)`
|
|
128
|
-
- `end` streaming has completed
|
|
129
|
-
|
|
130
|
-
#### .pipe
|
|
131
|
-
|
|
132
|
-
The `pipe` method is used to pipe the response into the Node.js HTTP response
|
|
133
|
-
object, typically `send(req, path, options).pipe(res)`.
|
|
134
|
-
|
|
135
|
-
## Error-handling
|
|
136
|
-
|
|
137
|
-
By default when no `error` listeners are present an automatic response will be
|
|
138
|
-
made, otherwise you have full control over the response, aka you may show a 5xx
|
|
139
|
-
page etc.
|
|
140
|
-
|
|
141
|
-
## Caching
|
|
142
|
-
|
|
143
|
-
It does _not_ perform internal caching, you should use a reverse proxy cache
|
|
144
|
-
such as Varnish for this, or those fancy things called CDNs. If your
|
|
145
|
-
application is small enough that it would benefit from single-node memory
|
|
146
|
-
caching, it's small enough that it does not need caching at all ;).
|
|
147
|
-
|
|
148
|
-
## Debugging
|
|
149
|
-
|
|
150
|
-
To enable `debug()` instrumentation output export __DEBUG__:
|
|
151
|
-
|
|
152
|
-
```
|
|
153
|
-
$ DEBUG=send node app
|
|
154
|
-
```
|
|
155
|
-
|
|
156
|
-
## Running tests
|
|
157
|
-
|
|
158
|
-
```
|
|
159
|
-
$ npm install
|
|
160
|
-
$ npm test
|
|
161
|
-
```
|
|
162
|
-
|
|
163
|
-
## Examples
|
|
164
|
-
|
|
165
|
-
### Serve a specific file
|
|
166
|
-
|
|
167
|
-
This simple example will send a specific file to all requests.
|
|
168
|
-
|
|
169
|
-
```js
|
|
170
|
-
var http = require('http')
|
|
171
|
-
var send = require('send')
|
|
172
|
-
|
|
173
|
-
var server = http.createServer(function onRequest (req, res) {
|
|
174
|
-
send(req, '/path/to/index.html')
|
|
175
|
-
.pipe(res)
|
|
176
|
-
})
|
|
177
|
-
|
|
178
|
-
server.listen(3000)
|
|
179
|
-
```
|
|
180
|
-
|
|
181
|
-
### Serve all files from a directory
|
|
182
|
-
|
|
183
|
-
This simple example will just serve up all the files in a
|
|
184
|
-
given directory as the top-level. For example, a request
|
|
185
|
-
`GET /foo.txt` will send back `/www/public/foo.txt`.
|
|
186
|
-
|
|
187
|
-
```js
|
|
188
|
-
var http = require('http')
|
|
189
|
-
var parseUrl = require('parseurl')
|
|
190
|
-
var send = require('send')
|
|
191
|
-
|
|
192
|
-
var server = http.createServer(function onRequest (req, res) {
|
|
193
|
-
send(req, parseUrl(req).pathname, { root: '/www/public' })
|
|
194
|
-
.pipe(res)
|
|
195
|
-
})
|
|
196
|
-
|
|
197
|
-
server.listen(3000)
|
|
198
|
-
```
|
|
199
|
-
|
|
200
|
-
### Custom file types
|
|
201
|
-
|
|
202
|
-
```js
|
|
203
|
-
var extname = require('path').extname
|
|
204
|
-
var http = require('http')
|
|
205
|
-
var parseUrl = require('parseurl')
|
|
206
|
-
var send = require('send')
|
|
207
|
-
|
|
208
|
-
var server = http.createServer(function onRequest (req, res) {
|
|
209
|
-
send(req, parseUrl(req).pathname, { root: '/www/public' })
|
|
210
|
-
.on('headers', function (res, path) {
|
|
211
|
-
switch (extname(path)) {
|
|
212
|
-
case '.x-mt':
|
|
213
|
-
case '.x-mtt':
|
|
214
|
-
// custom type for these extensions
|
|
215
|
-
res.setHeader('Content-Type', 'application/x-my-type')
|
|
216
|
-
break
|
|
217
|
-
}
|
|
218
|
-
})
|
|
219
|
-
.pipe(res)
|
|
220
|
-
})
|
|
221
|
-
|
|
222
|
-
server.listen(3000)
|
|
223
|
-
```
|
|
224
|
-
|
|
225
|
-
### Custom directory index view
|
|
226
|
-
|
|
227
|
-
This is an example of serving up a structure of directories with a
|
|
228
|
-
custom function to render a listing of a directory.
|
|
229
|
-
|
|
230
|
-
```js
|
|
231
|
-
var http = require('http')
|
|
232
|
-
var fs = require('fs')
|
|
233
|
-
var parseUrl = require('parseurl')
|
|
234
|
-
var send = require('send')
|
|
235
|
-
|
|
236
|
-
// Transfer arbitrary files from within /www/example.com/public/*
|
|
237
|
-
// with a custom handler for directory listing
|
|
238
|
-
var server = http.createServer(function onRequest (req, res) {
|
|
239
|
-
send(req, parseUrl(req).pathname, { index: false, root: '/www/public' })
|
|
240
|
-
.once('directory', directory)
|
|
241
|
-
.pipe(res)
|
|
242
|
-
})
|
|
243
|
-
|
|
244
|
-
server.listen(3000)
|
|
245
|
-
|
|
246
|
-
// Custom directory handler
|
|
247
|
-
function directory (res, path) {
|
|
248
|
-
var stream = this
|
|
249
|
-
|
|
250
|
-
// redirect to trailing slash for consistent url
|
|
251
|
-
if (!stream.hasTrailingSlash()) {
|
|
252
|
-
return stream.redirect(path)
|
|
253
|
-
}
|
|
254
|
-
|
|
255
|
-
// get directory list
|
|
256
|
-
fs.readdir(path, function onReaddir (err, list) {
|
|
257
|
-
if (err) return stream.error(err)
|
|
258
|
-
|
|
259
|
-
// render an index for the directory
|
|
260
|
-
res.setHeader('Content-Type', 'text/plain; charset=UTF-8')
|
|
261
|
-
res.end(list.join('\n') + '\n')
|
|
262
|
-
})
|
|
263
|
-
}
|
|
264
|
-
```
|
|
265
|
-
|
|
266
|
-
### Serving from a root directory with custom error-handling
|
|
267
|
-
|
|
268
|
-
```js
|
|
269
|
-
var http = require('http')
|
|
270
|
-
var parseUrl = require('parseurl')
|
|
271
|
-
var send = require('send')
|
|
272
|
-
|
|
273
|
-
var server = http.createServer(function onRequest (req, res) {
|
|
274
|
-
// your custom error-handling logic:
|
|
275
|
-
function error (err) {
|
|
276
|
-
res.statusCode = err.status || 500
|
|
277
|
-
res.end(err.message)
|
|
278
|
-
}
|
|
279
|
-
|
|
280
|
-
// your custom headers
|
|
281
|
-
function headers (res, path, stat) {
|
|
282
|
-
// serve all files for download
|
|
283
|
-
res.setHeader('Content-Disposition', 'attachment')
|
|
284
|
-
}
|
|
285
|
-
|
|
286
|
-
// your custom directory handling logic:
|
|
287
|
-
function redirect () {
|
|
288
|
-
res.statusCode = 301
|
|
289
|
-
res.setHeader('Location', req.url + '/')
|
|
290
|
-
res.end('Redirecting to ' + req.url + '/')
|
|
291
|
-
}
|
|
292
|
-
|
|
293
|
-
// transfer arbitrary files from within
|
|
294
|
-
// /www/example.com/public/*
|
|
295
|
-
send(req, parseUrl(req).pathname, { root: '/www/public' })
|
|
296
|
-
.on('error', error)
|
|
297
|
-
.on('directory', redirect)
|
|
298
|
-
.on('headers', headers)
|
|
299
|
-
.pipe(res)
|
|
300
|
-
})
|
|
301
|
-
|
|
302
|
-
server.listen(3000)
|
|
303
|
-
```
|
|
304
|
-
|
|
305
|
-
## License
|
|
306
|
-
|
|
307
|
-
[MIT](LICENSE)
|
|
308
|
-
|
|
309
|
-
[coveralls-image]: https://badgen.net/coveralls/c/github/pillarjs/send/master
|
|
310
|
-
[coveralls-url]: https://coveralls.io/r/pillarjs/send?branch=master
|
|
311
|
-
[github-actions-ci-image]: https://badgen.net/github/checks/pillarjs/send/master?label=linux
|
|
312
|
-
[github-actions-ci-url]: https://github.com/pillarjs/send/actions/workflows/ci.yml
|
|
313
|
-
[node-image]: https://badgen.net/npm/node/send
|
|
314
|
-
[node-url]: https://nodejs.org/en/download/
|
|
315
|
-
[npm-downloads-image]: https://badgen.net/npm/dm/send
|
|
316
|
-
[npm-url]: https://npmjs.org/package/send
|
|
317
|
-
[npm-version-image]: https://badgen.net/npm/v/send
|
|
@@ -1,253 +0,0 @@
|
|
|
1
|
-
# serve-static
|
|
2
|
-
|
|
3
|
-
[![NPM Version][npm-version-image]][npm-url]
|
|
4
|
-
[![NPM Downloads][npm-downloads-image]][npm-url]
|
|
5
|
-
[![CI][github-actions-ci-image]][github-actions-ci-url]
|
|
6
|
-
[![Test Coverage][coveralls-image]][coveralls-url]
|
|
7
|
-
|
|
8
|
-
## Install
|
|
9
|
-
|
|
10
|
-
This is a [Node.js](https://nodejs.org/en/) module available through the
|
|
11
|
-
[npm registry](https://www.npmjs.com/). Installation is done using the
|
|
12
|
-
[`npm install` command](https://docs.npmjs.com/getting-started/installing-npm-packages-locally):
|
|
13
|
-
|
|
14
|
-
```sh
|
|
15
|
-
$ npm install serve-static
|
|
16
|
-
```
|
|
17
|
-
|
|
18
|
-
## API
|
|
19
|
-
|
|
20
|
-
```js
|
|
21
|
-
const serveStatic = require('serve-static')
|
|
22
|
-
```
|
|
23
|
-
|
|
24
|
-
### serveStatic(root, options)
|
|
25
|
-
|
|
26
|
-
Create a new middleware function to serve files from within a given root
|
|
27
|
-
directory. The file to serve will be determined by combining `req.url`
|
|
28
|
-
with the provided root directory. When a file is not found, instead of
|
|
29
|
-
sending a 404 response, this module will instead call `next()` to move on
|
|
30
|
-
to the next middleware, allowing for stacking and fall-backs.
|
|
31
|
-
|
|
32
|
-
#### Options
|
|
33
|
-
|
|
34
|
-
##### acceptRanges
|
|
35
|
-
|
|
36
|
-
Enable or disable accepting ranged requests, defaults to true.
|
|
37
|
-
Disabling this will not send `Accept-Ranges` and ignore the contents
|
|
38
|
-
of the `Range` request header.
|
|
39
|
-
|
|
40
|
-
##### cacheControl
|
|
41
|
-
|
|
42
|
-
Enable or disable setting `Cache-Control` response header, defaults to
|
|
43
|
-
true. Disabling this will ignore the `immutable` and `maxAge` options.
|
|
44
|
-
|
|
45
|
-
##### dotfiles
|
|
46
|
-
|
|
47
|
-
Set how "dotfiles" are treated when encountered. A dotfile is a file
|
|
48
|
-
or directory that begins with a dot ("."). Note this check is done on
|
|
49
|
-
the path itself without checking if the path actually exists on the
|
|
50
|
-
disk. If `root` is specified, only the dotfiles above the root are
|
|
51
|
-
checked (i.e. the root itself can be within a dotfile when set
|
|
52
|
-
to "deny").
|
|
53
|
-
|
|
54
|
-
- `'allow'` No special treatment for dotfiles.
|
|
55
|
-
- `'deny'` Deny a request for a dotfile and 403/`next()`.
|
|
56
|
-
- `'ignore'` Pretend like the dotfile does not exist and 404/`next()`.
|
|
57
|
-
|
|
58
|
-
The default value is `'ignore'`.
|
|
59
|
-
|
|
60
|
-
##### etag
|
|
61
|
-
|
|
62
|
-
Enable or disable etag generation, defaults to true.
|
|
63
|
-
|
|
64
|
-
##### extensions
|
|
65
|
-
|
|
66
|
-
Set file extension fallbacks. When set, if a file is not found, the given
|
|
67
|
-
extensions will be added to the file name and search for. The first that
|
|
68
|
-
exists will be served. Example: `['html', 'htm']`.
|
|
69
|
-
|
|
70
|
-
The default value is `false`.
|
|
71
|
-
|
|
72
|
-
##### fallthrough
|
|
73
|
-
|
|
74
|
-
Set the middleware to have client errors fall-through as just unhandled
|
|
75
|
-
requests, otherwise forward a client error. The difference is that client
|
|
76
|
-
errors like a bad request or a request to a non-existent file will cause
|
|
77
|
-
this middleware to simply `next()` to your next middleware when this value
|
|
78
|
-
is `true`. When this value is `false`, these errors (even 404s), will invoke
|
|
79
|
-
`next(err)`.
|
|
80
|
-
|
|
81
|
-
Typically `true` is desired such that multiple physical directories can be
|
|
82
|
-
mapped to the same web address or for routes to fill in non-existent files.
|
|
83
|
-
|
|
84
|
-
The value `false` can be used if this middleware is mounted at a path that
|
|
85
|
-
is designed to be strictly a single file system directory, which allows for
|
|
86
|
-
short-circuiting 404s for less overhead. This middleware will also reply to
|
|
87
|
-
all methods.
|
|
88
|
-
|
|
89
|
-
The default value is `true`.
|
|
90
|
-
|
|
91
|
-
##### immutable
|
|
92
|
-
|
|
93
|
-
Enable or disable the `immutable` directive in the `Cache-Control` response
|
|
94
|
-
header, defaults to `false`. If set to `true`, the `maxAge` option should
|
|
95
|
-
also be specified to enable caching. The `immutable` directive will prevent
|
|
96
|
-
supported clients from making conditional requests during the life of the
|
|
97
|
-
`maxAge` option to check if the file has changed.
|
|
98
|
-
|
|
99
|
-
##### index
|
|
100
|
-
|
|
101
|
-
By default this module will send "index.html" files in response to a request
|
|
102
|
-
on a directory. To disable this set `false` or to supply a new index pass a
|
|
103
|
-
string or an array in preferred order.
|
|
104
|
-
|
|
105
|
-
##### lastModified
|
|
106
|
-
|
|
107
|
-
Enable or disable `Last-Modified` header, defaults to true. Uses the file
|
|
108
|
-
system's last modified value.
|
|
109
|
-
|
|
110
|
-
##### maxAge
|
|
111
|
-
|
|
112
|
-
Provide a max-age in milliseconds for http caching, defaults to 0. This
|
|
113
|
-
can also be a string accepted by the [ms](https://www.npmjs.org/package/ms#readme)
|
|
114
|
-
module.
|
|
115
|
-
|
|
116
|
-
##### redirect
|
|
117
|
-
|
|
118
|
-
Redirect to trailing "/" when the pathname is a dir. Defaults to `true`.
|
|
119
|
-
|
|
120
|
-
##### setHeaders
|
|
121
|
-
|
|
122
|
-
Function to set custom headers on response. Alterations to the headers need to
|
|
123
|
-
occur synchronously. The function is called as `fn(res, path, stat)`, where
|
|
124
|
-
the arguments are:
|
|
125
|
-
|
|
126
|
-
- `res` the response object
|
|
127
|
-
- `path` the file path that is being sent
|
|
128
|
-
- `stat` the stat object of the file that is being sent
|
|
129
|
-
|
|
130
|
-
## Examples
|
|
131
|
-
|
|
132
|
-
### Serve files with vanilla node.js http server
|
|
133
|
-
|
|
134
|
-
```js
|
|
135
|
-
const finalhandler = require('finalhandler')
|
|
136
|
-
const http = require('http')
|
|
137
|
-
const serveStatic = require('serve-static')
|
|
138
|
-
|
|
139
|
-
// Serve up public/ftp folder
|
|
140
|
-
const serve = serveStatic('public/ftp', { index: ['index.html', 'index.htm'] })
|
|
141
|
-
|
|
142
|
-
// Create server
|
|
143
|
-
const server = http.createServer((req, res) => {
|
|
144
|
-
serve(req, res, finalhandler(req, res))
|
|
145
|
-
})
|
|
146
|
-
|
|
147
|
-
// Listen
|
|
148
|
-
server.listen(3000)
|
|
149
|
-
```
|
|
150
|
-
|
|
151
|
-
### Serve all files as downloads
|
|
152
|
-
|
|
153
|
-
```js
|
|
154
|
-
const contentDisposition = require('content-disposition')
|
|
155
|
-
const finalhandler = require('finalhandler')
|
|
156
|
-
const http = require('http')
|
|
157
|
-
const serveStatic = require('serve-static')
|
|
158
|
-
|
|
159
|
-
// Serve up public/ftp folder
|
|
160
|
-
const serve = serveStatic('public/ftp', {
|
|
161
|
-
index: false,
|
|
162
|
-
setHeaders: setHeaders
|
|
163
|
-
})
|
|
164
|
-
|
|
165
|
-
// Set header to force download
|
|
166
|
-
function setHeaders (res, path) {
|
|
167
|
-
res.setHeader('Content-Disposition', contentDisposition(path))
|
|
168
|
-
}
|
|
169
|
-
|
|
170
|
-
// Create server
|
|
171
|
-
const server = http.createServer((req, res) => {
|
|
172
|
-
serve(req, res, finalhandler(req, res))
|
|
173
|
-
})
|
|
174
|
-
|
|
175
|
-
// Listen
|
|
176
|
-
server.listen(3000)
|
|
177
|
-
```
|
|
178
|
-
|
|
179
|
-
### Serving using express
|
|
180
|
-
|
|
181
|
-
#### Simple
|
|
182
|
-
|
|
183
|
-
This is a simple example of using Express.
|
|
184
|
-
|
|
185
|
-
```js
|
|
186
|
-
const express = require('express')
|
|
187
|
-
const serveStatic = require('serve-static')
|
|
188
|
-
|
|
189
|
-
const app = express()
|
|
190
|
-
|
|
191
|
-
app.use(serveStatic('public/ftp', { index: ['default.html', 'default.htm'] }))
|
|
192
|
-
app.listen(3000)
|
|
193
|
-
```
|
|
194
|
-
|
|
195
|
-
#### Multiple roots
|
|
196
|
-
|
|
197
|
-
This example shows a simple way to search through multiple directories.
|
|
198
|
-
Files are searched for in `public-optimized/` first, then `public/` second
|
|
199
|
-
as a fallback.
|
|
200
|
-
|
|
201
|
-
```js
|
|
202
|
-
const express = require('express')
|
|
203
|
-
const path = require('path')
|
|
204
|
-
const serveStatic = require('serve-static')
|
|
205
|
-
|
|
206
|
-
const app = express()
|
|
207
|
-
|
|
208
|
-
app.use(serveStatic(path.join(__dirname, 'public-optimized')))
|
|
209
|
-
app.use(serveStatic(path.join(__dirname, 'public')))
|
|
210
|
-
app.listen(3000)
|
|
211
|
-
```
|
|
212
|
-
|
|
213
|
-
#### Different settings for paths
|
|
214
|
-
|
|
215
|
-
This example shows how to set a different max age depending on the served
|
|
216
|
-
file. In this example, HTML files are not cached, while everything else
|
|
217
|
-
is for 1 day.
|
|
218
|
-
|
|
219
|
-
```js
|
|
220
|
-
const express = require('express')
|
|
221
|
-
const path = require('path')
|
|
222
|
-
const serveStatic = require('serve-static')
|
|
223
|
-
|
|
224
|
-
const app = express()
|
|
225
|
-
|
|
226
|
-
app.use(serveStatic(path.join(__dirname, 'public'), {
|
|
227
|
-
maxAge: '1d',
|
|
228
|
-
setHeaders: setCustomCacheControl
|
|
229
|
-
}))
|
|
230
|
-
|
|
231
|
-
app.listen(3000)
|
|
232
|
-
|
|
233
|
-
function setCustomCacheControl (res, file) {
|
|
234
|
-
if (path.extname(file) === '.html') {
|
|
235
|
-
// Custom Cache-Control for HTML files
|
|
236
|
-
res.setHeader('Cache-Control', 'public, max-age=0')
|
|
237
|
-
}
|
|
238
|
-
}
|
|
239
|
-
```
|
|
240
|
-
|
|
241
|
-
## License
|
|
242
|
-
|
|
243
|
-
[MIT](LICENSE)
|
|
244
|
-
|
|
245
|
-
[coveralls-image]: https://badgen.net/coveralls/c/github/expressjs/serve-static/master
|
|
246
|
-
[coveralls-url]: https://coveralls.io/r/expressjs/serve-static?branch=master
|
|
247
|
-
[github-actions-ci-image]: https://badgen.net/github/checks/expressjs/serve-static/master?label=linux
|
|
248
|
-
[github-actions-ci-url]: https://github.com/expressjs/serve-static/actions/workflows/ci.yml
|
|
249
|
-
[node-image]: https://badgen.net/npm/node/serve-static
|
|
250
|
-
[node-url]: https://nodejs.org/en/download/
|
|
251
|
-
[npm-downloads-image]: https://badgen.net/npm/dm/serve-static
|
|
252
|
-
[npm-url]: https://npmjs.org/package/serve-static
|
|
253
|
-
[npm-version-image]: https://badgen.net/npm/v/serve-static
|
|
@@ -1,87 +0,0 @@
|
|
|
1
|
-
2.0.2 / 2025-06-06
|
|
2
|
-
==================
|
|
3
|
-
|
|
4
|
-
* Migrate to `String.prototype.slice()`
|
|
5
|
-
|
|
6
|
-
2.0.1 / 2021-01-03
|
|
7
|
-
==================
|
|
8
|
-
|
|
9
|
-
* Fix returning values from `Object.prototype`
|
|
10
|
-
|
|
11
|
-
2.0.0 / 2020-04-19
|
|
12
|
-
==================
|
|
13
|
-
|
|
14
|
-
* Drop support for Node.js 0.6
|
|
15
|
-
* Fix messaging casing of `418 I'm a Teapot`
|
|
16
|
-
* Remove code 306
|
|
17
|
-
* Remove `status[code]` exports; use `status.message[code]`
|
|
18
|
-
* Remove `status[msg]` exports; use `status.code[msg]`
|
|
19
|
-
* Rename `425 Unordered Collection` to standard `425 Too Early`
|
|
20
|
-
* Rename `STATUS_CODES` export to `message`
|
|
21
|
-
* Return status message for `statuses(code)` when given code
|
|
22
|
-
|
|
23
|
-
1.5.0 / 2018-03-27
|
|
24
|
-
==================
|
|
25
|
-
|
|
26
|
-
* Add `103 Early Hints`
|
|
27
|
-
|
|
28
|
-
1.4.0 / 2017-10-20
|
|
29
|
-
==================
|
|
30
|
-
|
|
31
|
-
* Add `STATUS_CODES` export
|
|
32
|
-
|
|
33
|
-
1.3.1 / 2016-11-11
|
|
34
|
-
==================
|
|
35
|
-
|
|
36
|
-
* Fix return type in JSDoc
|
|
37
|
-
|
|
38
|
-
1.3.0 / 2016-05-17
|
|
39
|
-
==================
|
|
40
|
-
|
|
41
|
-
* Add `421 Misdirected Request`
|
|
42
|
-
* perf: enable strict mode
|
|
43
|
-
|
|
44
|
-
1.2.1 / 2015-02-01
|
|
45
|
-
==================
|
|
46
|
-
|
|
47
|
-
* Fix message for status 451
|
|
48
|
-
- `451 Unavailable For Legal Reasons`
|
|
49
|
-
|
|
50
|
-
1.2.0 / 2014-09-28
|
|
51
|
-
==================
|
|
52
|
-
|
|
53
|
-
* Add `208 Already Repored`
|
|
54
|
-
* Add `226 IM Used`
|
|
55
|
-
* Add `306 (Unused)`
|
|
56
|
-
* Add `415 Unable For Legal Reasons`
|
|
57
|
-
* Add `508 Loop Detected`
|
|
58
|
-
|
|
59
|
-
1.1.1 / 2014-09-24
|
|
60
|
-
==================
|
|
61
|
-
|
|
62
|
-
* Add missing 308 to `codes.json`
|
|
63
|
-
|
|
64
|
-
1.1.0 / 2014-09-21
|
|
65
|
-
==================
|
|
66
|
-
|
|
67
|
-
* Add `codes.json` for universal support
|
|
68
|
-
|
|
69
|
-
1.0.4 / 2014-08-20
|
|
70
|
-
==================
|
|
71
|
-
|
|
72
|
-
* Package cleanup
|
|
73
|
-
|
|
74
|
-
1.0.3 / 2014-06-08
|
|
75
|
-
==================
|
|
76
|
-
|
|
77
|
-
* Add 308 to `.redirect` category
|
|
78
|
-
|
|
79
|
-
1.0.2 / 2014-03-13
|
|
80
|
-
==================
|
|
81
|
-
|
|
82
|
-
* Add `.retry` category
|
|
83
|
-
|
|
84
|
-
1.0.1 / 2014-03-12
|
|
85
|
-
==================
|
|
86
|
-
|
|
87
|
-
* Initial release
|