@fastify/static
Advanced tools
Comparing version 6.5.0 to 6.5.1
@@ -13,4 +13,4 @@ 'use strict' | ||
}) | ||
.listen(3000, err => { | ||
.listen({ port: 3000 }, err => { | ||
if (err) throw err | ||
}) |
@@ -47,4 +47,4 @@ 'use strict' | ||
}) | ||
.listen(3000, err => { | ||
.listen({ port: 3000 }, err => { | ||
if (err) throw err | ||
}) |
@@ -11,4 +11,4 @@ 'use strict' | ||
}) | ||
.listen(3000, err => { | ||
.listen({ port: 3000 }, err => { | ||
if (err) throw err | ||
}) |
@@ -521,1 +521,3 @@ 'use strict' | ||
}) | ||
module.exports.default = fastifyStatic | ||
module.exports.fastifyStatic = fastifyStatic |
{ | ||
"name": "@fastify/static", | ||
"version": "6.5.0", | ||
"version": "6.5.1", | ||
"description": "Plugin for serving static files as fast as possible.", | ||
"main": "index.js", | ||
"types": "index.d.ts", | ||
"types": "types/index.d.ts", | ||
"scripts": { | ||
@@ -42,2 +42,3 @@ "lint": "standard | snazzy", | ||
"@fastify/compress": "^6.0.0", | ||
"@fastify/pre-commit": "^2.0.2", | ||
"@types/node": "^18.0.0", | ||
@@ -51,3 +52,3 @@ "@typescript-eslint/eslint-plugin": "^2.29.0", | ||
"handlebars": "^4.7.6", | ||
"pre-commit": "^1.2.2", | ||
"pino": "^8.4.2", | ||
"proxyquire": "^2.1.0", | ||
@@ -58,4 +59,3 @@ "simple-get": "^4.0.0", | ||
"tap": "^16.0.0", | ||
"tsd": "^0.22.0", | ||
"typescript": "^4.0.2" | ||
"tsd": "^0.24.1" | ||
}, | ||
@@ -62,0 +62,0 @@ "tsd": { |
@@ -7,6 +7,10 @@ # @fastify/static | ||
Plugin for serving static files as fast as possible. Supports Fastify version `3.x`. | ||
Plugin for serving static files as fast as possible. Supports Fastify version `4.x`. | ||
Please refer to [this branch](https://github.com/fastify/fastify-static/tree/2.x) and related versions for Fastify `^2.0.0` compatibility. | ||
Please refer to [this branch](https://github.com/fastify/fastify-static/tree/1.x) and related versions for Fastify `^1.11.0` compatibility. | ||
| Fastify version | branch | | ||
| --------------- | -------------------------------------------------------------------- | | ||
| `^4.x` | This branch | | ||
| `^3.x` | [`v5.x`](https://github.com/fastify/fastify-static/tree/v5.x) | | ||
| `^2.x` | [`2.x`](https://github.com/fastify/fastify-static/tree/2.x) | | ||
| `^1.11.x` | [`1.x`](https://github.com/fastify/fastify-static/tree/1.x) | | ||
@@ -20,3 +24,3 @@ ## Install | ||
```js | ||
const fastify = require('fastify')() | ||
const fastify = require('fastify')({logger: true}) | ||
const path = require('path') | ||
@@ -30,12 +34,22 @@ | ||
fastify.get('/another/path', function (req, reply) { | ||
return reply.sendFile('myHtml.html') // serving path.join(__dirname, 'public', 'myHtml.html') directly | ||
reply.sendFile('myHtml.html') // serving path.join(__dirname, 'public', 'myHtml.html') directly | ||
}) | ||
fastify.get('/another/patch-async', async function (req, reply) { | ||
return reply.sendFile('myHtml.html') | ||
}) | ||
fastify.get('/path/with/different/root', function (req, reply) { | ||
return reply.sendFile('myHtml.html', path.join(__dirname, 'build')) // serving a file from a different root location | ||
reply.sendFile('myHtml.html', path.join(__dirname, 'build')) // serving a file from a different root location | ||
}) | ||
fastify.get('/another/path', function (req, reply) { | ||
return reply.sendFile('myHtml.html', { cacheControl: false }) // overriding the options disabling cache-control headers | ||
reply.sendFile('myHtml.html', { cacheControl: false }) // overriding the options disabling cache-control headers | ||
}) | ||
// Run the server! | ||
fastify.listen({ port: 3000 }, (err, address) => { | ||
if (err) throw err | ||
// Server is now listening on ${address} | ||
}) | ||
``` | ||
@@ -75,11 +89,16 @@ | ||
fastify.get('/another/path', function (req, reply) { | ||
return reply.download('myHtml.html', 'custom-filename.html') // sending path.join(__dirname, 'public', 'myHtml.html') directly with custom filename | ||
reply.download('myHtml.html', 'custom-filename.html') // sending path.join(__dirname, 'public', 'myHtml.html') directly with custom filename | ||
}) | ||
fastify.get('another/patch-async', async function (req, reply) { | ||
// an async handler must always return the reply object | ||
return reply.download('myHtml.html', 'custom-filename.html') | ||
}) | ||
fastify.get('/path/without/cache/control', function (req, reply) { | ||
return reply.download('myHtml.html', { cacheControl: false }) // serving a file disabling cache-control headers | ||
reply.download('myHtml.html', { cacheControl: false }) // serving a file disabling cache-control headers | ||
}) | ||
fastify.get('/path/without/cache/control', function (req, reply) { | ||
return reply.download('myHtml.html', 'custom-filename.html', { cacheControl: false }) | ||
reply.download('myHtml.html', 'custom-filename.html', { cacheControl: false }) | ||
}) | ||
@@ -86,0 +105,0 @@ |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is not supported yet
New author
Supply chain riskA new npm collaborator published a version of the package for the first time. New collaborators are usually benign additions to a project, but do indicate a change to the security surface area of a package.
Found 1 instance in 1 package
4793
461
1
354942
50