oipage 0.2.0-alpha.0 → 0.2.0-alpha.1
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 +2 -0
- package/README.md +0 -4
- package/browserjs/index.d.ts +3 -0
- package/browserjs/index.js +2 -0
- package/browserjs/setStyle/index.d.ts +10 -0
- package/browserjs/setStyle/index.js +5 -0
- package/nodejs/core/server.js +32 -19
- package/package.json +1 -1
package/CHANGELOG
CHANGED
package/README.md
CHANGED
package/browserjs/index.d.ts
CHANGED
|
@@ -1,10 +1,13 @@
|
|
|
1
1
|
import { getStyleType } from "./getStyle"
|
|
2
|
+
import { setStyleType } from "./setStyle"
|
|
2
3
|
import { onReadyType } from "./onReady"
|
|
3
4
|
|
|
4
5
|
export default class Corejs {
|
|
5
6
|
static getStyle: getStyleType
|
|
7
|
+
static setStyle: setStyleType
|
|
6
8
|
static onReady: onReadyType
|
|
7
9
|
}
|
|
8
10
|
|
|
9
11
|
export let getStyle: getStyleType
|
|
12
|
+
export let setStyle: setStyleType
|
|
10
13
|
export let onReady: onReadyType
|
package/browserjs/index.js
CHANGED
package/nodejs/core/server.js
CHANGED
|
@@ -44,12 +44,40 @@ module.exports = function (config = {}) {
|
|
|
44
44
|
request.on('end', () => {
|
|
45
45
|
let url = decodeURIComponent(request.url);
|
|
46
46
|
|
|
47
|
+
url = url.split("?")[0];
|
|
48
|
+
|
|
49
|
+
// 请求的文件路径
|
|
50
|
+
let filePath = path.join(basePath, url == "/" ? "index.html" : url.replace(/^\//, ""));
|
|
51
|
+
|
|
47
52
|
log("[" + index++ + "]" + url);
|
|
48
53
|
|
|
54
|
+
let getFileInfo = function (filePath) {
|
|
55
|
+
let dotName = /\./.test(filePath) ? filePath.match(/\.([^.]+)$/)[1] : "";
|
|
56
|
+
let type = mineTypes[dotName];
|
|
57
|
+
if (fs.existsSync(filePath) && !fs.lstatSync(filePath).isDirectory()) {
|
|
58
|
+
return {
|
|
59
|
+
type,
|
|
60
|
+
path: filePath
|
|
61
|
+
};
|
|
62
|
+
} else {
|
|
63
|
+
for (let suffix of suffixs) {
|
|
64
|
+
if (fs.existsSync(filePath + suffix) && !fs.lstatSync(filePath + suffix).isDirectory()) {
|
|
65
|
+
type = mineTypes[suffix.replace(/^\./, "")];
|
|
66
|
+
return {
|
|
67
|
+
type,
|
|
68
|
+
path: filePath + suffix
|
|
69
|
+
};
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
};
|
|
74
|
+
|
|
49
75
|
// 自定义拦截
|
|
50
76
|
if (handler.call({
|
|
51
77
|
data: requestData,
|
|
52
|
-
base: basePath
|
|
78
|
+
base: basePath,
|
|
79
|
+
getFileInfo,
|
|
80
|
+
filePath
|
|
53
81
|
}, request, response)) return;
|
|
54
82
|
|
|
55
83
|
// proxy拦截
|
|
@@ -101,13 +129,6 @@ module.exports = function (config = {}) {
|
|
|
101
129
|
}
|
|
102
130
|
}
|
|
103
131
|
|
|
104
|
-
url = url.split("?")[0];
|
|
105
|
-
|
|
106
|
-
// 请求的文件路径
|
|
107
|
-
let filePath = path.join(basePath, url == "/" ? "index.html" : url.replace(/^\//, ""));
|
|
108
|
-
|
|
109
|
-
let dotName = /\./.test(filePath) ? filePath.match(/\.([^.]+)$/)[1] : "";
|
|
110
|
-
|
|
111
132
|
let is404 = true;
|
|
112
133
|
let doResponse = function (type, filePath) {
|
|
113
134
|
response.writeHead(200, {
|
|
@@ -119,17 +140,9 @@ module.exports = function (config = {}) {
|
|
|
119
140
|
is404 = false;
|
|
120
141
|
};
|
|
121
142
|
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
doResponse(type, filePath);
|
|
126
|
-
} else {
|
|
127
|
-
for (let suffix of suffixs) {
|
|
128
|
-
if (fs.existsSync(filePath + suffix) && !fs.lstatSync(filePath + suffix).isDirectory()) {
|
|
129
|
-
type = mineTypes[suffix.replace(/^\./, "")];
|
|
130
|
-
doResponse(type, filePath + suffix);
|
|
131
|
-
}
|
|
132
|
-
}
|
|
143
|
+
let fileInfo = getFileInfo(filePath);
|
|
144
|
+
if (fileInfo) { // 如果文件存在
|
|
145
|
+
doResponse(fileInfo.type, fileInfo.path);
|
|
133
146
|
}
|
|
134
147
|
|
|
135
148
|
if (is404) {
|