@midwayjs/static-file 3.0.0-beta.16 → 3.0.2

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.
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2013 - Now midwayjs
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
@@ -0,0 +1 @@
1
+ {"version":3,"file":"config.default.js","sourceRoot":"","sources":["../../src/config/config.default.ts"],"names":[],"mappings":";;AACA,+BAA4B;AAE5B,kBAAe,OAAO,CAAC,EAAE;IACvB,OAAO;QACL,UAAU,EAAE;YACV,IAAI,EAAE;gBACJ,OAAO,EAAE;oBACP,MAAM,EAAE,SAAS;oBACjB,GAAG,EAAE,IAAA,WAAI,EAAC,OAAO,CAAC,MAAM,EAAE,QAAQ,CAAC;iBACpC;aACF;YACD,OAAO,EAAE,IAAI;YACb,OAAO,EAAE,KAAK;YACd,MAAM,EAAE,KAAK;YACb,QAAQ,EAAE,IAAI;SACf;KAGF,CAAC;AACJ,CAAC,CAAC","sourcesContent":["import { StaticFileOptions } from '../interface';\nimport { join } from 'path';\n\nexport default appInfo => {\n return {\n staticFile: {\n dirs: {\n default: {\n prefix: '/public',\n dir: join(appInfo.appDir, 'public'),\n },\n },\n dynamic: true,\n preload: false,\n buffer: false,\n maxFiles: 1000,\n },\n } as {\n staticFile: StaticFileOptions;\n };\n};\n"]}
@@ -1,5 +1,3 @@
1
- export declare const staticFile: {
2
- maxAge: number;
3
- buffer: boolean;
4
- };
1
+ import { StaticFileOptions } from '../interface';
2
+ export declare const staticFile: StaticFileOptions;
5
3
  //# sourceMappingURL=config.prod.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"config.prod.js","sourceRoot":"","sources":["../../src/config/config.prod.ts"],"names":[],"mappings":";;;AAEa,QAAA,UAAU,GAAG;IACxB,MAAM,EAAE,QAAQ;IAChB,MAAM,EAAE,IAAI;CACQ,CAAC","sourcesContent":["import { StaticFileOptions } from '../interface';\n\nexport const staticFile = {\n maxAge: 31536000,\n buffer: true,\n} as StaticFileOptions;\n"]}
@@ -0,0 +1 @@
1
+ {"version":3,"file":"configuration.js","sourceRoot":"","sources":["../src/configuration.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,mDAA4D;AAC5D,sEAAkE;AAClE,yCAA0D;AAC1D,yDAAyD;AAUzD,IAAa,uBAAuB,GAApC,MAAa,uBAAuB;IAIlC,KAAK,CAAC,OAAO;QACX,IAAI,CAAC,kBAAkB;aACpB,eAAe,CAAC,CAAC,KAAK,EAAE,MAAM,EAAE,KAAK,CAAC,CAAC;aACvC,OAAO,CAAC,GAAG,CAAC,EAAE;YACb,GAAG,CAAC,aAAa,EAAE,CAAC,WAAW,CAAC,oCAAgB,CAAC,CAAC;QACpD,CAAC,CAAC,CAAC;IACP,CAAC;CACF,CAAA;AATC;IADC,IAAA,kBAAM,GAAE;8BACW,+BAAwB;mEAAC;AAFlC,uBAAuB;IARnC,IAAA,yBAAa,EAAC;QACb,SAAS,EAAE,MAAM;QACjB,aAAa,EAAE;YACb;gBACE,OAAO,EAAE,aAAa;aACvB;SACF;KACF,CAAC;GACW,uBAAuB,CAWnC;AAXY,0DAAuB","sourcesContent":["import { Configuration, Inject } from '@midwayjs/decorator';\nimport { StaticMiddleware } from './middleware/static.middleware';\nimport { MidwayApplicationManager } from '@midwayjs/core';\nimport * as DefaultConfig from './config/config.default';\n\n@Configuration({\n namespace: 'info',\n importConfigs: [\n {\n default: DefaultConfig,\n },\n ],\n})\nexport class StaticFileConfiguration {\n @Inject()\n applicationManager: MidwayApplicationManager;\n\n async onReady() {\n this.applicationManager\n .getApplications(['koa', 'faas', 'egg'])\n .forEach(app => {\n app.getMiddleware().insertFirst(StaticMiddleware);\n });\n }\n}\n"]}
@@ -0,0 +1 @@
1
+ {"version":3,"file":"error.js","sourceRoot":"","sources":["../src/error.ts"],"names":[],"mappings":";;;AAAA,yCAAgE;AAEnD,QAAA,mBAAmB,GAAG,IAAA,wBAAiB,EAAC,aAAa,EAAE;IAClE,oBAAoB,EAAE,KAAK;CACnB,CAAC,CAAC;AAEZ,MAAa,sBAAuB,SAAQ,kBAAW;IACrD,YAAY,CAAS;QACnB,KAAK,CACH,QAAQ,CAAC,8BAA8B,EACvC,2BAAmB,CAAC,oBAAoB,CACzC,CAAC;IACJ,CAAC;CACF;AAPD,wDAOC","sourcesContent":["import { registerErrorCode, MidwayError } from '@midwayjs/core';\n\nexport const StaticFileErrorEnum = registerErrorCode('static_file', {\n DIRECTORY_NOT_EXISTS: 10000,\n} as const);\n\nexport class DirectoryNotFoundError extends MidwayError {\n constructor(p: string) {\n super(\n `Path ${p} not exist, please check it.`,\n StaticFileErrorEnum.DIRECTORY_NOT_EXISTS\n );\n }\n}\n"]}
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;AAAA,iDAA2E;AAAlE,8GAAA,uBAAuB,OAAiB;AACjD,iEAA+C;AAC/C,8CAA4B;AAC5B,0CAAwB","sourcesContent":["export { StaticFileConfiguration as Configuration } from './configuration';\nexport * from './middleware/static.middleware';\nexport * from './interface';\nexport * from './error';\n"]}
@@ -23,6 +23,10 @@ export interface StaticFileOption {
23
23
  * cache control max age for the files, 0 by default.
24
24
  */
25
25
  maxFiles?: number;
26
+ /**
27
+ * cache control max age for the files, 0 by default.
28
+ */
29
+ maxAge?: number;
26
30
  /**
27
31
  * optional cache control header. Overrides options.maxAge.
28
32
  */
@@ -0,0 +1 @@
1
+ {"version":3,"file":"interface.js","sourceRoot":"","sources":["../src/interface.ts"],"names":[],"mappings":"","sourcesContent":["export interface StaticFileOption {\n /**\n * url prefix\n */\n prefix?: string;\n /**\n * the directory you wish to serve\n */\n dir?: string;\n /**\n * dynamic load file which not cached on initialization.\n */\n dynamic?: boolean;\n /**\n * caches the assets on initialization or not, default to true. always work together with options.dynamic.\n */\n preload?: boolean;\n /**\n * store the files in memory instead of streaming from the filesystem on each request.\n */\n buffer?: boolean;\n /**\n * cache control max age for the files, 0 by default.\n */\n maxFiles?: number;\n /**\n * cache control max age for the files, 0 by default.\n */\n maxAge?: number;\n /**\n * optional cache control header. Overrides options.maxAge.\n */\n cacheControl?: string;\n /**\n * when request's accept-encoding include gzip, files will compressed by gzip.\n */\n gzip?: boolean;\n /**\n * object map of aliases\n */\n alias?: {\n [aliasName: string]: string;\n },\n /**\n * filter files at init dir, for example - skip non build (source) files. If array set - allow only listed files\n */\n filter?: Function | string[];\n}\n\n\nexport interface StaticFileOptions extends Omit<StaticFileOption, 'prefix' | 'dir'> {\n dirs?: {\n [pathName: string]: StaticFileOption;\n },\n}\n"]}
@@ -0,0 +1 @@
1
+ {"version":3,"file":"static.middleware.js","sourceRoot":"","sources":["../../src/middleware/static.middleware.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,mDAO6B;AAC7B,yCAAyD;AACzD,iCAAiC;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rB,OAAO,CAAC,IAAI,CAAC,UAAU,CAAC,MAAM,CAAC,CAAC;aACjC;YAED,0BAA0B;YAC1B,IAAI,CAAC,CAAC,MAAM,qBAAS,CAAC,MAAM,CAAC,UAAU,CAAC,GAAG,CAAC,CAAC,EAAE;gBAC7C,MAAM,IAAI,8BAAsB,CAAC,UAAU,CAAC,GAAG,CAAC,CAAC;aAClD;YAED,IAAI,CAAC,MAAM,CAAC,IAAI,CACd,mDAAmD,EACnD,UAAU,CAAC,MAAM,EACjB,UAAU,CAAC,GAAG,CACf,CAAC;YAEF,WAAW,CAAC,IAAI,CAAC,WAAW,CAAC,UAAU,CAAC,CAAC,CAAC;SAC3C;QAED,OAAO,MAAM,IAAI,CAAC,iBAAiB,CAAC,OAAO,CAAC,WAAW,EAAE,GAAG,EAAE,YAAY,CAAC,CAAC;IAC9E,CAAC;IAED,MAAM,CAAC,OAAO;QACZ,OAAO,YAAY,CAAC;IACtB,CAAC;CACF,CAAA;AA9DC;IADC,IAAA,kBAAM,EAAC,YAAY,CAAC;;0DACI;AAGzB;IADC,IAAA,kBAAM,GAAE;8BACU,8BAAuB;2DAAW;AAGrD;IADC,IAAA,kBAAM,EAAC,YAAY,CAAC;;gDACd;AARI,gBAAgB;IAD5B,IAAA,sBAAU,GAAE;GACA,gBAAgB,CAgE5B;AAhEY,4CAAgB","sourcesContent":["import {\n Config,\n Inject,\n Middleware,\n Types,\n Logger,\n FileUtils,\n} from '@midwayjs/decorator';\nimport { MidwayMiddlewareService } from '@midwayjs/core';\nimport * as assert from 'assert';\nimport * as staticCache from 'koa-static-cache';\nimport * as LRU from 'ylru';\nimport * as range from 'koa-range';\nimport { DirectoryNotFoundError } from '../error';\n\n@Middleware()\nexport class StaticMiddleware {\n @Config('staticFile')\n private staticFileConfig;\n\n @Inject()\n middlewareService: MidwayMiddlewareService<any, any>;\n\n @Logger('coreLogger')\n logger;\n\n async resolve(app) {\n const dirs = Object.values(this.staticFileConfig.dirs);\n if (this.staticFileConfig.dir) {\n dirs.push(this.staticFileConfig.dir);\n }\n const prefixs = [];\n\n function rangeMiddleware(ctx, next) {\n // if match static file, and use range middleware.\n const isMatch = prefixs.some(p => ctx.path.startsWith(p));\n if (isMatch) {\n return range(ctx, next);\n }\n return next();\n }\n\n const middlewares = [rangeMiddleware];\n\n for (const dirObj of dirs) {\n assert(\n Types.isObject(dirObj) || Types.isString(dirObj),\n '`config.static.dir` must be `string | Array<string|object>`.'\n );\n\n const newOptions = Object.assign({}, this.staticFileConfig, dirObj);\n\n if (newOptions.dynamic && !newOptions.files) {\n newOptions.files = new LRU(newOptions.maxFiles);\n }\n\n if (newOptions.prefix) {\n prefixs.push(newOptions.prefix);\n }\n\n // ensure directory exists\n if (!(await FileUtils.exists(newOptions.dir))) {\n throw new DirectoryNotFoundError(newOptions.dir);\n }\n\n this.logger.info(\n '[@midwayjs/static] starting static serve %s -> %s',\n newOptions.prefix,\n newOptions.dir\n );\n\n middlewares.push(staticCache(newOptions));\n }\n\n return await this.middlewareService.compose(middlewares, app, 'staticFile');\n }\n\n static getName() {\n return 'staticFile';\n }\n}\n"]}
package/package.json CHANGED
@@ -1,26 +1,27 @@
1
1
  {
2
2
  "name": "@midwayjs/static-file",
3
3
  "description": "midway static file component",
4
- "version": "3.0.0-beta.16",
4
+ "version": "3.0.2",
5
5
  "main": "dist/index",
6
6
  "typings": "index.d.ts",
7
7
  "files": [
8
8
  "dist/**/*.js",
9
9
  "dist/**/*.d.ts",
10
- "index.d.ts"
10
+ "index.d.ts",
11
+ "dist/**/*.js.map"
11
12
  ],
12
13
  "dependencies": {
13
14
  "koa-range": "0.3.0",
14
- "ylru": "1.2.1",
15
- "koa-static-cache": "5.1.4"
15
+ "koa-static-cache": "5.1.4",
16
+ "ylru": "1.2.1"
16
17
  },
17
18
  "devDependencies": {
18
- "@midwayjs/core": "^3.0.0-beta.16",
19
- "@midwayjs/decorator": "^3.0.0-beta.16",
20
- "@midwayjs/koa": "^3.0.0-beta.16",
21
- "@midwayjs/faas": "^3.0.0-beta.16",
22
- "@midwayjs/mock": "^3.0.0-beta.16",
23
- "@midwayjs/serverless-app": "^3.0.0-beta.16"
19
+ "@midwayjs/core": "^3.0.2",
20
+ "@midwayjs/decorator": "^3.0.2",
21
+ "@midwayjs/faas": "^3.0.2",
22
+ "@midwayjs/koa": "^3.0.2",
23
+ "@midwayjs/mock": "^3.0.2",
24
+ "@midwayjs/serverless-app": "^3.0.2"
24
25
  },
25
26
  "keywords": [
26
27
  "midway",
@@ -43,5 +44,6 @@
43
44
  "repository": {
44
45
  "type": "git",
45
46
  "url": "https://github.com/midwayjs/midway.git"
46
- }
47
+ },
48
+ "gitHead": "ca77247d229978a736e79bb208579c014ed226fc"
47
49
  }
package/CHANGELOG.md DELETED
@@ -1,135 +0,0 @@
1
- # Change Log
2
-
3
- All notable changes to this project will be documented in this file.
4
- See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
5
-
6
- # [3.0.0-beta.16](https://github.com/midwayjs/midway/compare/v3.0.0-beta.15...v3.0.0-beta.16) (2022-01-11)
7
-
8
- **Note:** Version bump only for package @midwayjs/info
9
-
10
-
11
-
12
-
13
-
14
- # [3.0.0-beta.15](https://github.com/midwayjs/midway/compare/v3.0.0-beta.14...v3.0.0-beta.15) (2022-01-07)
15
-
16
-
17
- ### Features
18
-
19
- * add info middleware ([#1530](https://github.com/midwayjs/midway/issues/1530)) ([7077f1d](https://github.com/midwayjs/midway/commit/7077f1d84355633a1c2fced35bfcc2152f42a7ac))
20
- * add secret filter ([#1531](https://github.com/midwayjs/midway/issues/1531)) ([ce77e48](https://github.com/midwayjs/midway/commit/ce77e4804aaffc18a0a091d3726e36d7ec1514b2))
21
-
22
-
23
-
24
-
25
-
26
- # [3.0.0-beta.14](https://github.com/midwayjs/midway/compare/v3.0.0-beta.13...v3.0.0-beta.14) (2022-01-04)
27
-
28
- **Note:** Version bump only for package @midwayjs/info
29
-
30
-
31
-
32
-
33
-
34
- # [3.0.0-beta.13](https://github.com/midwayjs/midway/compare/v3.0.0-beta.12...v3.0.0-beta.13) (2021-12-30)
35
-
36
- **Note:** Version bump only for package @midwayjs/info
37
-
38
-
39
-
40
-
41
-
42
- # [3.0.0-beta.12](https://github.com/midwayjs/midway/compare/v3.0.0-beta.11...v3.0.0-beta.12) (2021-12-28)
43
-
44
- **Note:** Version bump only for package @midwayjs/info
45
-
46
-
47
-
48
-
49
-
50
- # [3.0.0-beta.11](https://github.com/midwayjs/midway/compare/v3.0.0-beta.10...v3.0.0-beta.11) (2021-12-21)
51
-
52
- **Note:** Version bump only for package @midwayjs/info
53
-
54
-
55
-
56
-
57
-
58
- # [3.0.0-beta.10](https://github.com/midwayjs/midway/compare/v3.0.0-beta.9...v3.0.0-beta.10) (2021-12-20)
59
-
60
- **Note:** Version bump only for package @midwayjs/info
61
-
62
-
63
-
64
-
65
-
66
- # [3.0.0-beta.9](https://github.com/midwayjs/midway/compare/v3.0.0-beta.8...v3.0.0-beta.9) (2021-12-09)
67
-
68
- **Note:** Version bump only for package @midwayjs/info
69
-
70
-
71
-
72
-
73
-
74
- # [3.0.0-beta.8](https://github.com/midwayjs/midway/compare/v3.0.0-beta.7...v3.0.0-beta.8) (2021-12-08)
75
-
76
- **Note:** Version bump only for package @midwayjs/info
77
-
78
-
79
-
80
-
81
-
82
- # [3.0.0-beta.7](https://github.com/midwayjs/midway/compare/v3.0.0-beta.6...v3.0.0-beta.7) (2021-12-03)
83
-
84
- **Note:** Version bump only for package @midwayjs/info
85
-
86
-
87
-
88
-
89
-
90
- # [3.0.0-beta.6](https://github.com/midwayjs/midway/compare/v3.0.0-beta.5...v3.0.0-beta.6) (2021-11-26)
91
-
92
- **Note:** Version bump only for package @midwayjs/info
93
-
94
-
95
-
96
-
97
-
98
- # [3.0.0-beta.5](https://github.com/midwayjs/midway/compare/v3.0.0-beta.4...v3.0.0-beta.5) (2021-11-25)
99
-
100
- **Note:** Version bump only for package @midwayjs/info
101
-
102
-
103
-
104
-
105
-
106
- # [3.0.0-beta.4](https://github.com/midwayjs/midway/compare/v3.0.0-beta.3...v3.0.0-beta.4) (2021-11-24)
107
-
108
- **Note:** Version bump only for package @midwayjs/info
109
-
110
-
111
-
112
-
113
-
114
- # [3.0.0-beta.3](https://github.com/midwayjs/midway/compare/v3.0.0-beta.2...v3.0.0-beta.3) (2021-11-18)
115
-
116
-
117
- ### Features
118
-
119
- * add component and framework config definition ([#1367](https://github.com/midwayjs/midway/issues/1367)) ([b2fe615](https://github.com/midwayjs/midway/commit/b2fe6157f99659471ff1333eca0b86bb889f61a3))
120
-
121
-
122
-
123
-
124
-
125
- # [3.0.0-beta.2](https://github.com/midwayjs/midway/compare/v3.0.0-beta.1...v3.0.0-beta.2) (2021-11-16)
126
-
127
- **Note:** Version bump only for package @midwayjs/info
128
-
129
-
130
-
131
-
132
-
133
- # [3.0.0-beta.1](https://github.com/midwayjs/midway/compare/v2.12.4...v3.0.0-beta.1) (2021-11-14)
134
-
135
- **Note:** Version bump only for package @midwayjs/info