Skip to content

Commit

Permalink
fix(opts): filter now optional and matches whole url (#23)
Browse files Browse the repository at this point in the history
* HASTILY_STREAMABLE_PATH_REGEXP now matches the whole URL (making it compatible
  with Express middleware paths)
* hasSupportedExtension now tests against the Express `req.originalUrl` instead
  of `req.path`, so it can be used in early Express middlewares before the
  `req.path` is populated
  • Loading branch information
zetlen committed Jan 21, 2021
1 parent 7547639 commit bb35c6f
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions src/lib/imageopto.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ HASTILY_STREAMABLE_FILETYPES.add('jpg');
// minus SVGs, which are widely supported in 2019 and we should not rasterize
HASTILY_STREAMABLE_FILETYPES.delete('svg');
export const HASTILY_STREAMABLE_PATH_REGEXP = new RegExp(
`\\.(?:${[...HASTILY_STREAMABLE_FILETYPES].join('|')})$`
`/.+\\.(${[...HASTILY_STREAMABLE_FILETYPES].join('|')})(?:[?#].*)?`
);

/**
Expand All @@ -64,7 +64,7 @@ export const HASTILY_STREAMABLE_PATH_REGEXP = new RegExp(
* @param req {Request}
*/
export const hasSupportedExtension: RequestFilter = (req) =>
HASTILY_STREAMABLE_PATH_REGEXP.test(req.path);
HASTILY_STREAMABLE_PATH_REGEXP.test(req.originalUrl);

/**
* Returns a new imageopto middleware for use in Express `app.use()`.
Expand Down

0 comments on commit bb35c6f

Please sign in to comment.