@midwayjs/static-file 3.18.0 → 3.19.0
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.
|
@@ -1,7 +1,8 @@
|
|
|
1
|
-
import { MidwayMiddlewareService } from '@midwayjs/core';
|
|
1
|
+
import { MidwayMiddlewareService, MidwayEnvironmentService } from '@midwayjs/core';
|
|
2
2
|
export declare class StaticMiddleware {
|
|
3
3
|
private staticFileConfig;
|
|
4
4
|
middlewareService: MidwayMiddlewareService<any, any>;
|
|
5
|
+
environmentService: MidwayEnvironmentService;
|
|
5
6
|
logger: any;
|
|
6
7
|
resolve(app: any): Promise<{
|
|
7
8
|
(context: any, next?: any): Promise<any>;
|
|
@@ -16,6 +16,7 @@ const staticCache = require("koa-static-cache");
|
|
|
16
16
|
const LRU = require("ylru");
|
|
17
17
|
const range = require("koa-range");
|
|
18
18
|
const error_1 = require("../error");
|
|
19
|
+
const fs = require("fs");
|
|
19
20
|
let StaticMiddleware = class StaticMiddleware {
|
|
20
21
|
async resolve(app) {
|
|
21
22
|
const dirs = Object.values(this.staticFileConfig.dirs);
|
|
@@ -42,8 +43,15 @@ let StaticMiddleware = class StaticMiddleware {
|
|
|
42
43
|
prefixs.push(newOptions.prefix);
|
|
43
44
|
}
|
|
44
45
|
// ensure directory exists
|
|
45
|
-
if (
|
|
46
|
-
|
|
46
|
+
if (this.environmentService.isPkgEnvironment()) {
|
|
47
|
+
if (!fs.existsSync(newOptions.dir)) {
|
|
48
|
+
throw new error_1.DirectoryNotFoundError(newOptions.dir);
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
else {
|
|
52
|
+
if (!(await core_1.FileUtils.exists(newOptions.dir))) {
|
|
53
|
+
throw new error_1.DirectoryNotFoundError(newOptions.dir);
|
|
54
|
+
}
|
|
47
55
|
}
|
|
48
56
|
this.logger.info('[midway:static] starting static serve %s -> %s', newOptions.prefix, newOptions.dir);
|
|
49
57
|
middlewares.push(staticCache(newOptions));
|
|
@@ -62,6 +70,10 @@ __decorate([
|
|
|
62
70
|
(0, core_1.Inject)(),
|
|
63
71
|
__metadata("design:type", core_1.MidwayMiddlewareService)
|
|
64
72
|
], StaticMiddleware.prototype, "middlewareService", void 0);
|
|
73
|
+
__decorate([
|
|
74
|
+
(0, core_1.Inject)(),
|
|
75
|
+
__metadata("design:type", core_1.MidwayEnvironmentService)
|
|
76
|
+
], StaticMiddleware.prototype, "environmentService", void 0);
|
|
65
77
|
__decorate([
|
|
66
78
|
(0, core_1.Logger)('coreLogger'),
|
|
67
79
|
__metadata("design:type", Object)
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@midwayjs/static-file",
|
|
3
3
|
"description": "midway static file component",
|
|
4
|
-
"version": "3.
|
|
4
|
+
"version": "3.19.0",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"typings": "index.d.ts",
|
|
7
7
|
"files": [
|
|
@@ -15,11 +15,11 @@
|
|
|
15
15
|
"ylru": "1.4.0"
|
|
16
16
|
},
|
|
17
17
|
"devDependencies": {
|
|
18
|
-
"@midwayjs/core": "^3.
|
|
19
|
-
"@midwayjs/faas": "^3.
|
|
20
|
-
"@midwayjs/koa": "^3.
|
|
21
|
-
"@midwayjs/mock": "^3.
|
|
22
|
-
"@midwayjs/serverless-app": "^3.
|
|
18
|
+
"@midwayjs/core": "^3.19.0",
|
|
19
|
+
"@midwayjs/faas": "^3.19.0",
|
|
20
|
+
"@midwayjs/koa": "^3.19.0",
|
|
21
|
+
"@midwayjs/mock": "^3.19.0",
|
|
22
|
+
"@midwayjs/serverless-app": "^3.19.0"
|
|
23
23
|
},
|
|
24
24
|
"keywords": [
|
|
25
25
|
"midway",
|
|
@@ -43,5 +43,5 @@
|
|
|
43
43
|
"type": "git",
|
|
44
44
|
"url": "https://github.com/midwayjs/midway.git"
|
|
45
45
|
},
|
|
46
|
-
"gitHead": "
|
|
46
|
+
"gitHead": "437e92d9375b0e375f83aa363f3e6a60187c7109"
|
|
47
47
|
}
|