wgt-node-utils 1.2.52 → 1.2.55
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/README.md +21 -2
- package/dist/bundle.js +1 -1
- package/package.json +1 -1
- package/src/index.js +48 -10
package/package.json
CHANGED
package/src/index.js
CHANGED
|
@@ -108,13 +108,12 @@ class wgtNodeUtils {
|
|
|
108
108
|
}
|
|
109
109
|
return system;
|
|
110
110
|
}
|
|
111
|
-
|
|
112
|
-
// 获取cloud front传回的设备信息
|
|
111
|
+
// 获取search site传回的设备信息
|
|
113
112
|
getSearchSiteSystem = (device) => {
|
|
114
113
|
const system = {
|
|
115
|
-
isAndroid: device,
|
|
116
|
-
isPhone: device,
|
|
117
|
-
isTablet: device
|
|
114
|
+
isAndroid: device === 'true',
|
|
115
|
+
isPhone: device === 'true',
|
|
116
|
+
isTablet: device === 'true'
|
|
118
117
|
};
|
|
119
118
|
|
|
120
119
|
// 其它设备均为空的情况下,默认当前设置为pc
|
|
@@ -124,6 +123,40 @@ class wgtNodeUtils {
|
|
|
124
123
|
return system;
|
|
125
124
|
}
|
|
126
125
|
|
|
126
|
+
// 获取template配置
|
|
127
|
+
// 判断当前是否是search模版
|
|
128
|
+
// @req 请求体
|
|
129
|
+
getGetTemplateConfiguration = (req) => {
|
|
130
|
+
const Env = req.headers['x-wgt-env'] || 'prod';
|
|
131
|
+
const isSearchSite = req.headers['x-from-search'] === 'true' || false;
|
|
132
|
+
const hostname = isSearchSite ? req.headers['x-forwarded-host'] : req.hostname;
|
|
133
|
+
const device = this.getCloudFrontDevice(req.headers);
|
|
134
|
+
const system = isSearchSite ? this.getSearchSiteSystem(req.headers['x-is-mobile']) : this.getCloudFrontSystem(device);
|
|
135
|
+
const imgDomain = this.getImgDomainByHostname(hostname, Env);
|
|
136
|
+
return {
|
|
137
|
+
isSearchSite,
|
|
138
|
+
hostname,
|
|
139
|
+
system,
|
|
140
|
+
imgDomain
|
|
141
|
+
}
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
// 根据hostname 获取图片地址前缀
|
|
145
|
+
/**
|
|
146
|
+
*
|
|
147
|
+
* @param {string} hostname //网站域名
|
|
148
|
+
* @returns {string} imgDomain //图片地址前缀
|
|
149
|
+
*/
|
|
150
|
+
getImgDomainByHostname = (hostname, Env) => {
|
|
151
|
+
let needReplaceArr = [ 'pro', 'qa', 'dev', 'test', 'development' ];
|
|
152
|
+
if (needReplaceArr.includes(Env)) {
|
|
153
|
+
return `https://img.enjoy4fun.com`;
|
|
154
|
+
} else {
|
|
155
|
+
const mainDomain = this.getMainDomainByHostname(hostname);
|
|
156
|
+
return `https://img.${mainDomain}`;
|
|
157
|
+
}
|
|
158
|
+
}
|
|
159
|
+
|
|
127
160
|
/***
|
|
128
161
|
* 通用头信息添加
|
|
129
162
|
* @res node端 返回头
|
|
@@ -184,9 +217,9 @@ class wgtNodeUtils {
|
|
|
184
217
|
* @buildName 打包名称
|
|
185
218
|
* @version 打包版本号
|
|
186
219
|
* @dirname 项目的绝对地址
|
|
187
|
-
* @
|
|
220
|
+
* @useGlobal 是否需要 global.css
|
|
188
221
|
*/
|
|
189
|
-
readF2eFiles = (buildName, version, dirname) => {
|
|
222
|
+
readF2eFiles = (buildName, version, dirname, useGlobal = false) => {
|
|
190
223
|
console.log('静态资源:开始读取');
|
|
191
224
|
return new Promise((resolve, reject) => {
|
|
192
225
|
try {
|
|
@@ -209,8 +242,13 @@ class wgtNodeUtils {
|
|
|
209
242
|
|
|
210
243
|
// 增加preact依赖
|
|
211
244
|
this.fileContents['preact.min.js'] = fs.readFileSync(path.join(dirname, `../${buildName}/dist/preact.min.js`), 'utf8');
|
|
212
|
-
|
|
213
|
-
|
|
245
|
+
|
|
246
|
+
// 增加wgt-web-ui的css文件
|
|
247
|
+
if (useGlobal) {
|
|
248
|
+
// 获取wgt-web-ui的css文件
|
|
249
|
+
this.fileContents['global.css'] = fs.readFileSync(path.join(dirname, `../${buildName}/assets/global.css`), 'utf8');
|
|
250
|
+
}
|
|
251
|
+
|
|
214
252
|
|
|
215
253
|
console.log('静态资源列表:');
|
|
216
254
|
|
|
@@ -281,7 +319,7 @@ class wgtNodeUtils {
|
|
|
281
319
|
const match = hostname.match(/(?:.*\.)?([^.]+\.[^.]+)$/);
|
|
282
320
|
// 如果没有匹配到主域名,返回默认的主域名
|
|
283
321
|
if (!match || match.length < 2) {
|
|
284
|
-
return '
|
|
322
|
+
return '';
|
|
285
323
|
}
|
|
286
324
|
// 返回匹配到的主域名
|
|
287
325
|
return match[1];
|