wok-server 0.3.1 → 0.3.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/dist/mvc/index.js +11 -1
- package/dist/mvc/server.js +9 -0
- package/dist/mvc/static/static-handler.js +10 -0
- package/documentation/zh-cn/mvc.md +8 -3
- package/package.json +1 -1
- package/types/mvc/index.d.ts +5 -0
- package/types/mvc/server.d.ts +5 -0
- package/types/mvc/static/static-handler.d.ts +5 -0
package/dist/mvc/index.js
CHANGED
|
@@ -1,12 +1,22 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.stopWebServer = exports.startWebServer = void 0;
|
|
3
|
+
exports.stopWebServer = exports.startWebServer = exports.removeServerStaticCache = void 0;
|
|
4
4
|
const tslib_1 = require("tslib");
|
|
5
5
|
const server_1 = require("./server");
|
|
6
6
|
/**
|
|
7
7
|
* 服务实例.
|
|
8
8
|
*/
|
|
9
9
|
let SERVER;
|
|
10
|
+
/**
|
|
11
|
+
* 删除服务器静态缓存
|
|
12
|
+
* @param path 路径,必须以斜杠开头,如:/assets/index.js
|
|
13
|
+
*/
|
|
14
|
+
async function removeServerStaticCache(path) {
|
|
15
|
+
if (SERVER) {
|
|
16
|
+
SERVER.removeServerStaticCache(path);
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
exports.removeServerStaticCache = removeServerStaticCache;
|
|
10
20
|
/**
|
|
11
21
|
* 启动 web服务
|
|
12
22
|
* @param opts
|
package/dist/mvc/server.js
CHANGED
|
@@ -241,6 +241,15 @@ class WokServer {
|
|
|
241
241
|
}
|
|
242
242
|
return res;
|
|
243
243
|
}
|
|
244
|
+
/**
|
|
245
|
+
* 删除服务器端静态资源缓存
|
|
246
|
+
* @param path
|
|
247
|
+
*/
|
|
248
|
+
removeServerStaticCache(path) {
|
|
249
|
+
if (this.staticHandler) {
|
|
250
|
+
this.staticHandler.removeServerCache(path);
|
|
251
|
+
}
|
|
252
|
+
}
|
|
244
253
|
/**
|
|
245
254
|
* 停止
|
|
246
255
|
*/
|
|
@@ -351,5 +351,15 @@ class StaticHandler {
|
|
|
351
351
|
}
|
|
352
352
|
return { filePath, stats: fileStat, maxAge: matchedRule.cacheAge };
|
|
353
353
|
}
|
|
354
|
+
/**
|
|
355
|
+
* 删除服务器端静态资源缓存
|
|
356
|
+
* @param path
|
|
357
|
+
*/
|
|
358
|
+
removeServerCache(path) {
|
|
359
|
+
if (this.cache) {
|
|
360
|
+
this.cache.remove(path);
|
|
361
|
+
this.cache.remove(`gzip-${path}`);
|
|
362
|
+
}
|
|
363
|
+
}
|
|
354
364
|
}
|
|
355
365
|
exports.StaticHandler = StaticHandler;
|
|
@@ -577,10 +577,15 @@ dir 参数是映射文件目录的地址,可以是绝对路径,也可以是
|
|
|
577
577
|
| SERVER_STATIC_CACHE_ENABLE | 是否启用服务器缓存,默认 false |
|
|
578
578
|
| SERVER_STATIC_CACHE_MAX_AGE | 服务器缓存时间,单位秒,默认 600 |
|
|
579
579
|
| SERVER_STATIC_CACHE_MAX_FILE_SIZE | 最大可缓存的文件大小,支持语义化格式,如 10m 和 100k 等,默认 10m |
|
|
580
|
-
| SERVER_STATIC_CACHE_MAX_SIZE | 缓存最大空间,一旦超出将执行清理,同上支持语义化格式,默认
|
|
580
|
+
| SERVER_STATIC_CACHE_MAX_SIZE | 缓存最大空间,一旦超出将执行清理,同上支持语义化格式,默认 100m |
|
|
581
581
|
|
|
582
|
-
|
|
583
|
-
|
|
582
|
+
0.3.2 版本新增加了 removeServerStaticCache 函数,可以主动删除指定的服务器端静态缓存。
|
|
583
|
+
|
|
584
|
+
```ts
|
|
585
|
+
import {removeServerStaticCache} from 'wok-server'
|
|
586
|
+
|
|
587
|
+
removeServerStaticCache('/assets/index.js')
|
|
588
|
+
```
|
|
584
589
|
|
|
585
590
|
### 请求日志
|
|
586
591
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "wok-server",
|
|
3
|
-
"version": "0.3.
|
|
3
|
+
"version": "0.3.2",
|
|
4
4
|
"packageManager": "pnpm@8.9.0",
|
|
5
5
|
"description": "一个基于 NodeJs 和 TypeScript 的后端框架,轻量级、克制、简洁。A lightweight, restrained, and concise backend framework based on Node.js and TypeScript.",
|
|
6
6
|
"scripts": {
|
package/types/mvc/index.d.ts
CHANGED
package/types/mvc/server.d.ts
CHANGED