Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

silently does not work if the static files folder path contains ".gz" #26

Closed
yarick123 opened this issue Aug 29, 2018 · 2 comments
Closed
Assignees
Labels

Comments

@yarick123
Copy link

Hi,
I am trying to use the middleware express-static-gzip.

It seems, that I found a bug. If the name of the folder containing static gzipped files contains '.gz',
no pre-compressed content will be delivered.

Steps to reproduce:

  1. create folder "wwwroot.gzipped" in the application root
  2. put gzpped files into the folder, e.g. test.html.gz
  3. register the folder as express-static-gzip root folder:
    app.use("/", expressStaticGzip('/wwwroot.gzipped'));
  4. start the application, by me it works on localhost:8080
  5. try to get http://localhost:8080/test.html
  6. result: error 404, "Cannot GET /test.html"

Renaming the folder to "wwwroot-gzipped" helps to avoid the problem.

The error is in index.js;167

    /**
     * Adds the compression to the file's list of available compressions
     * @param {string} filePath
     * @param {Compression} compression
     */
    function addCompressionToFile(filePath, compression) {
// !! in the next line there is an error - fileExtension is removed also from the middle of filePath !!
        var srcFilePath = filePath.replace(compression.fileExtension, "").replace(rootFolder, "");
        var existingFile = files[srcFilePath];
        if (!existingFile) {
            files[srcFilePath] = { compressions: [compression] };
        } else {
            existingFile.compressions.push(compression);
        }
    }

So, in the line

        var srcFilePath = filePath.replace(compression.fileExtension, "").replace(rootFolder, "");

fileExtension is removed also from the middle of filePath :(

I am using

  • express-static-gzip version 1.1.1,
  • node.js version 8.11.1,
  • express version 4.16.3

Best regards
yarick123

@tkoenig89 tkoenig89 self-assigned this Sep 6, 2018
@tkoenig89 tkoenig89 added the bug label Sep 6, 2018
tkoenig89 pushed a commit that referenced this issue Sep 7, 2018
- issue #26
- renamed the test directory
tkoenig89 pushed a commit that referenced this issue Sep 7, 2018
- file extensions is replaced after removing the root directory
  part of the filepath
@tkoenig89
Copy link
Owner

Should be resolved. I published version 1.1.2 to npm which contains the fix.

@yarick123
Copy link
Author

Thank you, the new version works in my environment with /wwwroot.gzipped/ folder

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants