@smpx/koa-request 0.2.7 → 0.2.8

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (2) hide show
  1. package/package.json +1 -1
  2. package/staticPaths.js +12 -7
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@smpx/koa-request",
3
- "version": "0.2.7",
3
+ "version": "0.2.8",
4
4
  "description": "Handle basic tasks for koajs",
5
5
  "main": "index.js",
6
6
  "types": "index.d.ts",
package/staticPaths.js CHANGED
@@ -13,19 +13,18 @@ function getMiddleware(options) {
13
13
  }
14
14
 
15
15
  return async (ctx, next) => {
16
+ if (options.disabled) {
17
+ await next();
18
+ return;
19
+ }
20
+
16
21
  if (options.path === '/') {
17
22
  // root requires special handling to check if extension denotes a static path
18
- const matches = ctx.path.match(/^\/(.*)\.(jpg|jpeg|gif|png|ico|css|js|json|ttf|otf|eot|woff|svg|svgz|xml|html|txt|ogg|ogv|mp4|rss|atom|zip|tgz|gz|rar|bz2|doc|xls|exe|ppt|tar|mid|midi|wav|bmp|rtf)$/);
23
+ const matches = ctx.path.match(/^\/(.*)\.(jpg|jpeg|gif|png|webp|avif|jxl|ico|css|js|mjs|json|ttf|otf|eot|woff|woff2|svg|svgz|xml|html|txt|ogg|ogv|mp4|av1|webm|rss|atom|zip|tgz|gz|rar|bz2|doc|xls|exe|ppt|tar|mid|midi|wav|bmp|rtf)$/);
19
24
  if (!matches) {
20
25
  await next();
21
26
  return;
22
27
  }
23
-
24
- // skip the current path
25
- if (options.skip && options.skip(ctx)) {
26
- await next();
27
- return;
28
- }
29
28
  }
30
29
 
31
30
  // return if request path is not static
@@ -34,6 +33,12 @@ function getMiddleware(options) {
34
33
  return;
35
34
  }
36
35
 
36
+ // skip the current path
37
+ if (options.skip && options.skip(ctx)) {
38
+ await next();
39
+ return;
40
+ }
41
+
37
42
  // only GET or GET like methods are allowed
38
43
  if (!['get', 'head', 'options'].includes(ctx.method.toLowerCase())) {
39
44
  ctx.body = 'Method Not Allowed';