fastify-static
Advanced tools
Comparing version 4.2.3 to 4.2.4
14
index.js
'use strict' | ||
const path = require('path') | ||
const url = require('url') | ||
const statSync = require('fs').statSync | ||
@@ -155,5 +154,3 @@ const { PassThrough } = require('readable-stream') | ||
if (opts.redirect === true) { | ||
/* eslint node/no-deprecated-api: "off" */ | ||
const parsed = url.parse(request.raw.url) | ||
reply.redirect(301, parsed.pathname + '/' + (parsed.search || '')) | ||
reply.redirect(301, getRedirectUrl(request.raw.url)) | ||
} else { | ||
@@ -279,5 +276,3 @@ reply.callNotFound() | ||
fastify.get(opts.prefix, routeOpts, function (req, reply) { | ||
/* eslint node/no-deprecated-api: "off" */ | ||
const parsed = url.parse(req.raw.url) | ||
reply.redirect(301, parsed.pathname + '/' + (parsed.search || '')) | ||
reply.redirect(301, getRedirectUrl(req.raw.url)) | ||
}) | ||
@@ -441,2 +436,7 @@ } | ||
function getRedirectUrl (url) { | ||
const parsed = new URL(url, 'http://localhost.com/') | ||
return parsed.pathname + (parsed.pathname[parsed.pathname.length - 1] !== '/' ? '/' : '') + (parsed.search || '') | ||
} | ||
module.exports = fp(fastifyStatic, { | ||
@@ -443,0 +443,0 @@ fastify: '3.x', |
{ | ||
"name": "fastify-static", | ||
"version": "4.2.3", | ||
"version": "4.2.4", | ||
"description": "Plugin for serving static files as fast as possible.", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
@@ -74,7 +74,7 @@ # fastify-static | ||
fastify.get('/path/without/cache/control', function (req, reply) { | ||
return reply.sendFile('myHtml.html', { cacheControl: false }) // serving a file disabling cache-control headers | ||
return reply.download('myHtml.html', { cacheControl: false }) // serving a file disabling cache-control headers | ||
}) | ||
fastify.get('/path/without/cache/control', function (req, reply) { | ||
return reply.sendFile('myHtml.html', 'custom-filename.html', { cacheControl: false }) | ||
return reply.download('myHtml.html', 'custom-filename.html', { cacheControl: false }) | ||
}) | ||
@@ -177,2 +177,9 @@ | ||
#### `index` | ||
Default: `undefined` | ||
Under the hood we use [send](https://github.com/pillarjs/send#index) lib that by default supports "index.html" files. | ||
To disable this set false or to supply a new index pass a string or an array in preferred order. | ||
#### `list` | ||
@@ -192,2 +199,3 @@ | ||
prefix: '/public/', | ||
index: false | ||
list: true | ||
@@ -194,0 +202,0 @@ }) |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is too big to display
335739
3948
355
45