express-static-gzip
Advanced tools
Comparing version
@@ -0,1 +1,21 @@ | ||
// Type definitions for express-static-gzip 2.0 | ||
/* =================== USAGE =================== | ||
import * as expressStaticGzip from "express-static-gzip"; | ||
app.use(expressStaticGzip("wwwroot", {enableBrotli: true, index: 'index.htm'})) | ||
=============================================== */ | ||
import * as express from "express"; | ||
import * as serverStatic from "serve-static"; | ||
/** | ||
* Generates a middleware function to serve static files. It is build on top of serveStatic. | ||
* It extends serveStatic with the capability to serve (previously) gziped files. For this | ||
* it asumes, the gziped files are next to the original files. | ||
* @param root folder to staticly serve files from | ||
* @param options options to configure expressStaticGzip | ||
*/ | ||
declare function expressStaticGzip(root: string, options: expressStaticGzip.ExpressStaticGzipOptions): express.Handler; | ||
declare namespace expressStaticGzip { | ||
@@ -44,3 +64,3 @@ | ||
*/ | ||
serveStatic?: import('serve-static').ServeStaticOptions | ||
serveStatic?: serverStatic.ServeStaticOptions | ||
} | ||
@@ -59,2 +79,4 @@ | ||
} | ||
} | ||
} | ||
export = expressStaticGzip; |
14
index.js
@@ -9,10 +9,10 @@ let serveStatic = require('serve-static'); | ||
/** | ||
* Generates a middleware function to serve static files. It is build on top of the express.static middleware. | ||
* It extends the express.static middleware with the capability to serve (previously) gziped files. For this | ||
* Generates a middleware function to serve static files. It is build on top of serveStatic. | ||
* It extends serveStatic with the capability to serve (previously) gziped files. For this | ||
* it asumes, the gziped files are next to the original files. | ||
* @param {string} rootFolder: folder to staticly serve files from | ||
* @param {string} root: folder to staticly serve files from | ||
* @param {expressStaticGzip.ExpressStaticGzipOptions} options: options to change module behaviour | ||
* @returns express middleware function | ||
*/ | ||
function expressStaticGzip(rootFolder, options) { | ||
function expressStaticGzip(root, options) { | ||
// strip away unnecessary options | ||
@@ -22,3 +22,3 @@ let opts = sanitizeOptions(options); | ||
//create a express.static middleware to handle serving files | ||
let defaultStatic = serveStatic(rootFolder, opts.serveStatic || null); | ||
let defaultStatic = serveStatic(root, opts.serveStatic || null); | ||
let compressions = []; | ||
@@ -32,3 +32,3 @@ let files = {}; | ||
if (compressions.length > 0) { | ||
findAllCompressionFiles(require("fs"), rootFolder); | ||
findAllCompressionFiles(require("fs"), root); | ||
} | ||
@@ -170,3 +170,3 @@ | ||
function addCompressionToFile(filePath, compression) { | ||
var srcFilePath = filePath.replace(rootFolder, "").replace(compression.fileExtension, ""); | ||
var srcFilePath = filePath.replace(root, "").replace(compression.fileExtension, ""); | ||
var existingFile = files[srcFilePath]; | ||
@@ -173,0 +173,0 @@ if (!existingFile) { |
{ | ||
"name": "express-static-gzip", | ||
"version": "2.0.0", | ||
"version": "2.0.1", | ||
"description": "simple wrapper on top of express.static, that allows serving pre-gziped files", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
40882
2.1%723
2.26%