oipage 1.3.1-alpha.0 → 1.4.0-alpha.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.
- package/CHANGELOG +9 -1
- package/bin/serve.d.ts +55 -0
- package/bin/serve.js +15 -12
- package/nodejs/animation/index.js +1 -1
- package/nodejs/cmdlog/index.js +1 -1
- package/nodejs/disk/index.js +1 -1
- package/nodejs/json/index.js +1 -1
- package/nodejs/logform/index.js +1 -1
- package/nodejs/reader/index.js +1 -1
- package/nodejs/throttle/index.js +1 -1
- package/package.json +1 -1
- package/web/animation/index.js +1 -1
- package/web/json/index.js +1 -1
- package/web/onReady/index.js +1 -1
- package/web/performChunk/index.js +1 -1
- package/web/reader/index.js +1 -1
- package/web/style/index.js +1 -1
- package/web/throttle/index.js +1 -1
package/CHANGELOG
CHANGED
|
@@ -68,8 +68,16 @@ v1.3.0:(废弃,请用1.3.1代替)
|
|
|
68
68
|
* 新增 devServer.intercept 请求拦截
|
|
69
69
|
* 新增对 if-modified-since和last-modified 之304协商缓存的支持
|
|
70
70
|
v1.3.1:
|
|
71
|
-
date:
|
|
71
|
+
date:2025-05-23
|
|
72
72
|
changes:
|
|
73
73
|
- 修复bug
|
|
74
74
|
1、开发服务器
|
|
75
75
|
* 由于是否入口判断导致import语句未正确解析
|
|
76
|
+
* 修复 Last-Modified 格式不规范导致的运行报错
|
|
77
|
+
v1.4.0:
|
|
78
|
+
date:
|
|
79
|
+
changes:
|
|
80
|
+
- 新增功能
|
|
81
|
+
1、开发服务器
|
|
82
|
+
* 新增 serve.d.ts 以支持作为API在TypeScript中环境
|
|
83
|
+
(仅对内使用,未正式对外暴露API相关文档)
|
package/bin/serve.d.ts
ADDED
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
|
|
2
|
+
interface DevServerType {
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* 服务器端口号
|
|
6
|
+
*/
|
|
7
|
+
port?: number
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
* 服务器根路径
|
|
11
|
+
*/
|
|
12
|
+
baseUrl?: string
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
interface InterceptType {
|
|
16
|
+
test: RegExp
|
|
17
|
+
handler(request: any, response: any): void
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
interface LoaderType {
|
|
21
|
+
(source: string): string
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
interface ConfigType {
|
|
25
|
+
|
|
26
|
+
/**
|
|
27
|
+
* 服务器名称
|
|
28
|
+
*/
|
|
29
|
+
name?: string
|
|
30
|
+
|
|
31
|
+
/**
|
|
32
|
+
* 服务器版本
|
|
33
|
+
*/
|
|
34
|
+
version?: string
|
|
35
|
+
|
|
36
|
+
/**
|
|
37
|
+
* 服务器运行配置
|
|
38
|
+
*/
|
|
39
|
+
devServer?: DevServerType
|
|
40
|
+
|
|
41
|
+
intercept?: Array<InterceptType>
|
|
42
|
+
|
|
43
|
+
module?: {
|
|
44
|
+
rules: Array<{
|
|
45
|
+
test: RegExp
|
|
46
|
+
use: LoaderType
|
|
47
|
+
}>
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
interface ServeType {
|
|
52
|
+
(config: ConfigType): void
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
export default ServeType
|
package/bin/serve.js
CHANGED
|
@@ -15,6 +15,9 @@ module.exports = function (config) {
|
|
|
15
15
|
const port = config.devServer.port; // 端口号
|
|
16
16
|
const basePath = (/^\./.test(config.devServer.baseUrl)) ? join(process.cwd(), config.devServer.baseUrl) : config.devServer.baseUrl; // 服务器根路径
|
|
17
17
|
|
|
18
|
+
const name = (config.name || "OIPage") + "-http-server";
|
|
19
|
+
const version = config.version || packageValue.version;
|
|
20
|
+
|
|
18
21
|
let Server = createServer(function (request, response) {
|
|
19
22
|
let headers = request.headers;
|
|
20
23
|
let url = decodeURIComponent(request.url);
|
|
@@ -27,7 +30,7 @@ module.exports = function (config) {
|
|
|
27
30
|
|
|
28
31
|
// 请求拦截
|
|
29
32
|
if (doIntercept(url.replace(/^\/@modules\//, ""), config.devServer.intercept, request, response)) {
|
|
30
|
-
console.log("<i> \x1b[1m\x1b[32m[
|
|
33
|
+
console.log("<i> \x1b[1m\x1b[32m[" + name + "] intercept: " + url + '\x1b[0m ' + new Date().toLocaleString());
|
|
31
34
|
}
|
|
32
35
|
|
|
33
36
|
// 如果存在且是文件
|
|
@@ -37,12 +40,12 @@ module.exports = function (config) {
|
|
|
37
40
|
let fileType = mineTypes[dotName]; // 文件类型
|
|
38
41
|
let fileInfo = statSync(filePath);
|
|
39
42
|
|
|
40
|
-
let fileModifiedTime = new Date(fileInfo.mtime).
|
|
43
|
+
let fileModifiedTime = new Date(fileInfo.mtime).toGMTString();
|
|
41
44
|
|
|
42
45
|
let responseHeader = {
|
|
43
46
|
'Content-type': (fileType || "text/plain") + ";charset=utf-8",
|
|
44
47
|
'Access-Control-Allow-Origin': '*',
|
|
45
|
-
'Server': 'Powered by
|
|
48
|
+
'Server': 'Powered by ' + name + '@' + version,
|
|
46
49
|
'Cache-Control': 'no-cache',
|
|
47
50
|
'Last-Modified': fileModifiedTime
|
|
48
51
|
};
|
|
@@ -53,7 +56,7 @@ module.exports = function (config) {
|
|
|
53
56
|
if (lastModified <= ifModifiedSince) {
|
|
54
57
|
response.writeHead('304', responseHeader);
|
|
55
58
|
response.end();
|
|
56
|
-
console.log("<i> \x1b[1m\x1b[32m[
|
|
59
|
+
console.log("<i> \x1b[1m\x1b[32m[" + name + "] Cache File: " + url + "\x1b[0m " + new Date().toLocaleString() + "\x1b[33m\x1b[1m 304\x1b[0m");
|
|
57
60
|
return;
|
|
58
61
|
}
|
|
59
62
|
}
|
|
@@ -98,7 +101,7 @@ module.exports = function (config) {
|
|
|
98
101
|
createReadStream(filePath).pipe(response);
|
|
99
102
|
}
|
|
100
103
|
|
|
101
|
-
console.log("<i> \x1b[1m\x1b[32m[
|
|
104
|
+
console.log("<i> \x1b[1m\x1b[32m[" + name + "] " + sendType + " File: " + url + '\x1b[0m ' + new Date().toLocaleString());
|
|
102
105
|
}
|
|
103
106
|
|
|
104
107
|
// 否则就是404
|
|
@@ -106,7 +109,7 @@ module.exports = function (config) {
|
|
|
106
109
|
response.writeHead(404, {
|
|
107
110
|
'Content-type': "text/html;charset=utf-8",
|
|
108
111
|
'Access-Control-Allow-Origin': '*',
|
|
109
|
-
'Server': 'Powered by
|
|
112
|
+
'Server': 'Powered by ' + name + '@' + version
|
|
110
113
|
});
|
|
111
114
|
response.write(resolve404(filePath, url));
|
|
112
115
|
response.end();
|
|
@@ -120,10 +123,10 @@ module.exports = function (config) {
|
|
|
120
123
|
let networkValue = network();
|
|
121
124
|
|
|
122
125
|
// 打印成功提示
|
|
123
|
-
console.log('<i> \x1b[1m\x1b[32m[
|
|
124
|
-
console.log('<i> \x1b[1m\x1b[32m[
|
|
125
|
-
for (let ipv4Item of networkValue.IPv4) console.log('<i> \x1b[1m\x1b[32m[
|
|
126
|
-
for (let ipv6Item of networkValue.IPv6) console.log('<i> \x1b[1m\x1b[32m[
|
|
127
|
-
console.log('<i> \x1b[1m\x1b[32m[
|
|
128
|
-
console.log('\
|
|
126
|
+
console.log('<i> \x1b[1m\x1b[32m[' + name + '] Project is running at:\x1b[0m');
|
|
127
|
+
console.log('<i> \x1b[1m\x1b[32m[' + name + '] Loopback: \x1b[36mhttp://localhost:' + port + '/\x1b[0m');
|
|
128
|
+
for (let ipv4Item of networkValue.IPv4) console.log('<i> \x1b[1m\x1b[32m[' + name + '] On Your Network (IPv4):\x1b[36m http://' + ipv4Item.address + ':' + port + '/\x1b[0m');
|
|
129
|
+
for (let ipv6Item of networkValue.IPv6) console.log('<i> \x1b[1m\x1b[32m[' + name + '] On Your Network (IPv6): \x1b[36mhttp://[' + ipv6Item.address + ']:' + port + '/\x1b[0m');
|
|
130
|
+
console.log('<i> \x1b[1m\x1b[32m[' + name + '] Content not from ' + (config.name || "OIPage") + ' is served from \x1b[36m"' + basePath + '" \x1b[0mdirectory');
|
|
131
|
+
console.log('\n' + (config.name || "OIPage") + ' ' + version + ' compiled \x1b[1m\x1b[32msuccessfully\x1b[0m in ' + (new Date().valueOf() - startTime) + ' ms\n')
|
|
129
132
|
};
|
package/nodejs/cmdlog/index.js
CHANGED
package/nodejs/disk/index.js
CHANGED
package/nodejs/json/index.js
CHANGED
package/nodejs/logform/index.js
CHANGED
package/nodejs/reader/index.js
CHANGED
package/nodejs/throttle/index.js
CHANGED
package/package.json
CHANGED
package/web/animation/index.js
CHANGED
package/web/json/index.js
CHANGED
package/web/onReady/index.js
CHANGED
package/web/reader/index.js
CHANGED
package/web/style/index.js
CHANGED
package/web/throttle/index.js
CHANGED