@midwayjs/static-file 3.0.3 → 3.0.6
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/package.json +9 -10
- package/dist/config/config.default.js.map +0 -1
- package/dist/config/config.prod.js.map +0 -1
- package/dist/configuration.js.map +0 -1
- package/dist/error.js.map +0 -1
- package/dist/index.js.map +0 -1
- package/dist/interface.js.map +0 -1
- package/dist/middleware/static.middleware.js.map +0 -1
package/package.json
CHANGED
|
@@ -1,14 +1,13 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@midwayjs/static-file",
|
|
3
3
|
"description": "midway static file component",
|
|
4
|
-
"version": "3.0.
|
|
4
|
+
"version": "3.0.6",
|
|
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"
|
|
11
|
-
"dist/**/*.js.map"
|
|
10
|
+
"index.d.ts"
|
|
12
11
|
],
|
|
13
12
|
"dependencies": {
|
|
14
13
|
"koa-range": "0.3.0",
|
|
@@ -16,12 +15,12 @@
|
|
|
16
15
|
"ylru": "1.2.1"
|
|
17
16
|
},
|
|
18
17
|
"devDependencies": {
|
|
19
|
-
"@midwayjs/core": "^3.0.
|
|
20
|
-
"@midwayjs/decorator": "^3.0.
|
|
21
|
-
"@midwayjs/faas": "^3.0.
|
|
22
|
-
"@midwayjs/koa": "^3.0.
|
|
23
|
-
"@midwayjs/mock": "^3.0.
|
|
24
|
-
"@midwayjs/serverless-app": "^3.0.
|
|
18
|
+
"@midwayjs/core": "^3.0.6",
|
|
19
|
+
"@midwayjs/decorator": "^3.0.6",
|
|
20
|
+
"@midwayjs/faas": "^3.0.6",
|
|
21
|
+
"@midwayjs/koa": "^3.0.6",
|
|
22
|
+
"@midwayjs/mock": "^3.0.6",
|
|
23
|
+
"@midwayjs/serverless-app": "^3.0.6"
|
|
25
24
|
},
|
|
26
25
|
"keywords": [
|
|
27
26
|
"midway",
|
|
@@ -45,5 +44,5 @@
|
|
|
45
44
|
"type": "git",
|
|
46
45
|
"url": "https://github.com/midwayjs/midway.git"
|
|
47
46
|
},
|
|
48
|
-
"gitHead": "
|
|
47
|
+
"gitHead": "afaa5b59a2be85e915233a9268c0e05965dd5c61"
|
|
49
48
|
}
|
|
@@ -1 +0,0 @@
|
|
|
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 +0,0 @@
|
|
|
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"]}
|
|
@@ -1 +0,0 @@
|
|
|
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"]}
|
package/dist/error.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
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"]}
|
package/dist/index.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
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"]}
|
package/dist/interface.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
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"]}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"static.middleware.js","sourceRoot":"","sources":["../../src/middleware/static.middleware.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,mDAO6B;AAC7B,yCAAyD;AACzD,iCAAiC;AACjC,gDAAgD;AAChD,4BAA4B;AAC5B,mCAAmC;AACnC,oCAAkD;AAGlD,IAAa,gBAAgB,GAA7B,MAAa,gBAAgB;IAU3B,KAAK,CAAC,OAAO,CAAC,GAAG;QACf,MAAM,IAAI,GAAG,MAAM,CAAC,MAAM,CAAC,IAAI,CAAC,gBAAgB,CAAC,IAAI,CAAC,CAAC;QACvD,IAAI,IAAI,CAAC,gBAAgB,CAAC,GAAG,EAAE;YAC7B,IAAI,CAAC,IAAI,CAAC,IAAI,CAAC,gBAAgB,CAAC,GAAG,CAAC,CAAC;SACtC;QACD,MAAM,OAAO,GAAG,EAAE,CAAC;QAEnB,SAAS,eAAe,CAAC,GAAG,EAAE,IAAI;YAChC,kDAAkD;YAClD,MAAM,OAAO,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,CAAC,GAAG,CAAC,IAAI,CAAC,UAAU,CAAC,CAAC,CAAC,CAAC,CAAC;YAC1D,IAAI,OAAO,EAAE;gBACX,OAAO,KAAK,CAAC,GAAG,EAAE,IAAI,CAAC,CAAC;aACzB;YACD,OAAO,IAAI,EAAE,CAAC;QAChB,CAAC;QAED,MAAM,WAAW,GAAG,CAAC,eAAe,CAAC,CAAC;QAEtC,KAAK,MAAM,MAAM,IAAI,IAAI,EAAE;YACzB,M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E5B;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"]}
|