@metricinsights/pp-dev 0.9.0 → 0.10.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.md +144 -0
- package/README.md +152 -232
- package/dist/cjs/cli.js +1 -1200
- package/dist/cjs/cli.js.map +1 -1
- package/dist/cjs/helpers.js +1 -28
- package/dist/cjs/helpers.js.map +1 -1
- package/dist/cjs/index-DRre2UkM.js +2 -0
- package/dist/cjs/index-DRre2UkM.js.map +1 -0
- package/dist/cjs/index.js +1 -26
- package/dist/cjs/index.js.map +1 -1
- package/dist/cjs/package.json +19 -14
- package/dist/cjs/plugin-Dx9CDaej.js +2 -0
- package/dist/cjs/plugin-Dx9CDaej.js.map +1 -0
- package/dist/cjs/plugin.js +1 -25
- package/dist/cjs/plugin.js.map +1 -1
- package/dist/client/client.css +3 -287
- package/dist/client/client.css.map +1 -0
- package/dist/client/client.js +110 -14
- package/dist/client/client.js.map +1 -1
- package/dist/client/index.html +39 -26
- package/dist/esm/cli.js +1 -1173
- package/dist/esm/cli.js.map +1 -1
- package/dist/esm/helpers.js +1 -24
- package/dist/esm/helpers.js.map +1 -1
- package/dist/esm/index-kmS_-y6Z.js +2 -0
- package/dist/esm/index-kmS_-y6Z.js.map +1 -0
- package/dist/esm/index.js +1 -19
- package/dist/esm/index.js.map +1 -1
- package/dist/esm/package.json +19 -14
- package/dist/esm/plugin-H4ccpQoX.js +2 -0
- package/dist/esm/plugin-H4ccpQoX.js.map +1 -0
- package/dist/esm/plugin.js +1 -16
- package/dist/esm/plugin.js.map +1 -1
- package/dist/types/index.d.ts +104 -3
- package/package.json +19 -14
- package/dist/cjs/index-BE4YF5iw.js +0 -331
- package/dist/cjs/index-BE4YF5iw.js.map +0 -1
- package/dist/cjs/plugin-DZS4Taov.js +0 -1315
- package/dist/cjs/plugin-DZS4Taov.js.map +0 -1
- package/dist/client/index.d.ts +0 -2
- package/dist/esm/index-7YgmP5z7.js +0 -308
- package/dist/esm/index-7YgmP5z7.js.map +0 -1
- package/dist/esm/plugin-BeHiwpzF.js +0 -1277
- package/dist/esm/plugin-BeHiwpzF.js.map +0 -1
- package/dist/types/cli.d.ts +0 -3
- package/dist/types/helpers.d.ts +0 -24
- package/dist/types/plugin.d.ts +0 -86
|
@@ -1,1277 +0,0 @@
|
|
|
1
|
-
import { createProxyMiddleware, responseInterceptor } from 'http-proxy-middleware';
|
|
2
|
-
import { fileURLToPath, URL as URL$1 } from 'url';
|
|
3
|
-
import { createLogger as createLogger$1 } from 'vite';
|
|
4
|
-
import { createColors } from 'picocolors';
|
|
5
|
-
import axios from 'axios';
|
|
6
|
-
import { JSDOM } from 'jsdom';
|
|
7
|
-
import { Agent } from 'https';
|
|
8
|
-
import * as memoryCache from 'memory-cache';
|
|
9
|
-
import * as path from 'path';
|
|
10
|
-
import { promises } from 'fs';
|
|
11
|
-
import * as crypto from 'crypto';
|
|
12
|
-
import * as process$1 from 'process';
|
|
13
|
-
import * as child_process from 'child_process';
|
|
14
|
-
import * as console from 'console';
|
|
15
|
-
import { deflateSync, brotliDecompressSync, unzipSync, inflateSync, brotliCompressSync, gzipSync } from 'zlib';
|
|
16
|
-
|
|
17
|
-
const urlReplacer = (originalHost, destinationHost, content) => {
|
|
18
|
-
const urlReplaceRegExp = new RegExp(`(!!)?(https?(:(\\\\)?/(\\\\)?/)${originalHost})`, 'gi');
|
|
19
|
-
return content.replace(urlReplaceRegExp, (substring, ...args) => {
|
|
20
|
-
if (substring.startsWith('!!')) {
|
|
21
|
-
return args[1];
|
|
22
|
-
}
|
|
23
|
-
return `http${args[2]}${destinationHost}`;
|
|
24
|
-
});
|
|
25
|
-
};
|
|
26
|
-
const urlPathReplacer = (urlPath, destinationPath, content) => {
|
|
27
|
-
const urlReplaceRegExp = new RegExp(`${urlPath.replace(/\\*\//gi, '\\\\/')}`, 'gi');
|
|
28
|
-
return content.replace(urlReplaceRegExp, destinationPath);
|
|
29
|
-
};
|
|
30
|
-
const redirect = (res, url, statusCode) => {
|
|
31
|
-
res.setHeader('location', url);
|
|
32
|
-
res.statusCode = statusCode;
|
|
33
|
-
res.end();
|
|
34
|
-
};
|
|
35
|
-
function cutUrlParams(url) {
|
|
36
|
-
const urlParts = url.split('?');
|
|
37
|
-
return urlParts[0];
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
// import pino from 'pino';
|
|
41
|
-
// import { PrettyOptions } from 'pino-pretty';
|
|
42
|
-
const storage = new Map();
|
|
43
|
-
const DEFAULT_LOGGER_KEY = 'default';
|
|
44
|
-
const createLogger = (level = 'info', name = DEFAULT_LOGGER_KEY) => {
|
|
45
|
-
if (storage.has(name)) {
|
|
46
|
-
return storage.get(name);
|
|
47
|
-
}
|
|
48
|
-
if (name === DEFAULT_LOGGER_KEY) {
|
|
49
|
-
const logger = createLogger$1(level);
|
|
50
|
-
storage.set(name, logger);
|
|
51
|
-
return logger;
|
|
52
|
-
}
|
|
53
|
-
const logger = createLogger$1(level);
|
|
54
|
-
storage.set(name, logger);
|
|
55
|
-
return logger;
|
|
56
|
-
};
|
|
57
|
-
|
|
58
|
-
const colors = createColors();
|
|
59
|
-
|
|
60
|
-
const hostOriginRegExp = /^(https?:\/\/)([^/]+)(\/.*)?$/i;
|
|
61
|
-
const PROXY_HEADER = 'X-PP-Proxy';
|
|
62
|
-
// TODO: Implement interceptor for streaming responses
|
|
63
|
-
function streamResponseInterceptor(interceptor) {
|
|
64
|
-
return async (proxyRes, req, res) => {
|
|
65
|
-
res.setHeader(PROXY_HEADER, 1);
|
|
66
|
-
res.setHeaders(new Map(Object.entries(proxyRes.headers)));
|
|
67
|
-
proxyRes.pipe(res);
|
|
68
|
-
};
|
|
69
|
-
}
|
|
70
|
-
function initProxy(opts) {
|
|
71
|
-
const { rewritePath = /^\/(?!pt).*/i, baseURL = '', devServer, disableSSLValidation = false } = opts;
|
|
72
|
-
if (!baseURL) {
|
|
73
|
-
throw new Error('Base url is required');
|
|
74
|
-
}
|
|
75
|
-
const host = baseURL.replace(hostOriginRegExp, '$2');
|
|
76
|
-
const origin = baseURL.replace(hostOriginRegExp, '$1$2');
|
|
77
|
-
const fileType = import('file-type');
|
|
78
|
-
const logger = createLogger();
|
|
79
|
-
return createProxyMiddleware({
|
|
80
|
-
/**
|
|
81
|
-
* IMPORTANT: avoid res.end being called automatically
|
|
82
|
-
**/
|
|
83
|
-
selfHandleResponse: true, // res.end() will be called internally by responseInterceptor()
|
|
84
|
-
pathFilter: (pathname, req) => {
|
|
85
|
-
if ((opts.proxyIgnore || []).some((value) => {
|
|
86
|
-
if (typeof value === 'string') {
|
|
87
|
-
return pathname.startsWith(value);
|
|
88
|
-
}
|
|
89
|
-
else if (typeof value.test === 'function') {
|
|
90
|
-
return value.test(pathname);
|
|
91
|
-
}
|
|
92
|
-
return true;
|
|
93
|
-
})) {
|
|
94
|
-
// Ignored paths
|
|
95
|
-
return false;
|
|
96
|
-
}
|
|
97
|
-
if (typeof rewritePath === 'string') {
|
|
98
|
-
return pathname.startsWith(rewritePath);
|
|
99
|
-
}
|
|
100
|
-
else if (Array.isArray(rewritePath)) {
|
|
101
|
-
return rewritePath.some((rP) => pathname.startsWith(rP));
|
|
102
|
-
}
|
|
103
|
-
else if (typeof rewritePath.test === 'function') {
|
|
104
|
-
return rewritePath.test(pathname);
|
|
105
|
-
}
|
|
106
|
-
return false;
|
|
107
|
-
},
|
|
108
|
-
target: baseURL,
|
|
109
|
-
changeOrigin: true,
|
|
110
|
-
autoRewrite: true,
|
|
111
|
-
cookieDomainRewrite: {
|
|
112
|
-
[host]: 'localhost',
|
|
113
|
-
},
|
|
114
|
-
logger: {
|
|
115
|
-
info: () => {
|
|
116
|
-
//
|
|
117
|
-
},
|
|
118
|
-
log: () => {
|
|
119
|
-
//
|
|
120
|
-
},
|
|
121
|
-
error: () => {
|
|
122
|
-
//
|
|
123
|
-
},
|
|
124
|
-
warn: () => {
|
|
125
|
-
//
|
|
126
|
-
},
|
|
127
|
-
},
|
|
128
|
-
secure: !disableSSLValidation,
|
|
129
|
-
headers: {
|
|
130
|
-
host,
|
|
131
|
-
origin,
|
|
132
|
-
},
|
|
133
|
-
on: {
|
|
134
|
-
proxyReq(proxyReq, req, res) {
|
|
135
|
-
const host = req.headers.host;
|
|
136
|
-
const referer = proxyReq.getHeader('referer');
|
|
137
|
-
logger.info(`${colors.blue('Proxies request:')} ${colors.green(req.method)} ${req.url} -> ${colors.green(proxyReq.method)} ${proxyReq.protocol}//${proxyReq.host}${proxyReq.path}`);
|
|
138
|
-
if (host && referer && typeof referer === 'string') {
|
|
139
|
-
proxyReq.setHeader('referer', referer.replace(new RegExp(`https?://${host}`), baseURL));
|
|
140
|
-
}
|
|
141
|
-
req.socket.on('close', () => {
|
|
142
|
-
setTimeout(() => {
|
|
143
|
-
if (!proxyReq.destroyed) {
|
|
144
|
-
proxyReq.destroy();
|
|
145
|
-
}
|
|
146
|
-
}, 200);
|
|
147
|
-
});
|
|
148
|
-
return proxyReq;
|
|
149
|
-
},
|
|
150
|
-
proxyRes: (serverRes, req, res) => {
|
|
151
|
-
if (serverRes.headers['content-type']?.includes('text/event-stream') ||
|
|
152
|
-
(serverRes.headers['transfer-encoding']?.includes('chunked') &&
|
|
153
|
-
serverRes.headers['x-accel-buffering'] === 'no')) {
|
|
154
|
-
logger.info(`${colors.blue('Start streaming for request:')} ${colors.green(req.method)} ${req.url}`);
|
|
155
|
-
const streamInterceptor = streamResponseInterceptor();
|
|
156
|
-
return streamInterceptor(serverRes, req, res);
|
|
157
|
-
}
|
|
158
|
-
const rewriteInterceptor = responseInterceptor(async (responseBuffer, proxyRes, req, res) => {
|
|
159
|
-
res.setHeader(PROXY_HEADER, 1);
|
|
160
|
-
const type = await (await fileType).fileTypeFromBuffer(responseBuffer);
|
|
161
|
-
if (type) {
|
|
162
|
-
return responseBuffer;
|
|
163
|
-
}
|
|
164
|
-
else {
|
|
165
|
-
let response = responseBuffer.toString('utf8'); // convert buffer to string
|
|
166
|
-
try {
|
|
167
|
-
const reqUrl = new URL(req.url ?? '', `http://${host}`);
|
|
168
|
-
if (reqUrl.searchParams && reqUrl.searchParams.has('proxyRedirect')) {
|
|
169
|
-
const redirectToFunction = function () {
|
|
170
|
-
let url = window.location.href;
|
|
171
|
-
const func = function () {
|
|
172
|
-
const params = new URLSearchParams(window.location.search);
|
|
173
|
-
if (!params.has('proxyRedirect')) {
|
|
174
|
-
return;
|
|
175
|
-
}
|
|
176
|
-
if (url !== window.location.href) {
|
|
177
|
-
url = window.location.href;
|
|
178
|
-
setTimeout(func, 2000);
|
|
179
|
-
}
|
|
180
|
-
else {
|
|
181
|
-
window.location.href = params.get('proxyRedirect');
|
|
182
|
-
}
|
|
183
|
-
};
|
|
184
|
-
setTimeout(func, 2000);
|
|
185
|
-
};
|
|
186
|
-
response += '<script>' + `(${redirectToFunction.toString()})()` + '</script>';
|
|
187
|
-
}
|
|
188
|
-
}
|
|
189
|
-
catch {
|
|
190
|
-
//
|
|
191
|
-
}
|
|
192
|
-
const reqHost = req.headers.host ?? '';
|
|
193
|
-
// manipulate response and return the result
|
|
194
|
-
return urlPathReplacer('/auth/saml/login', '/login', urlReplacer(host, reqHost, response));
|
|
195
|
-
}
|
|
196
|
-
});
|
|
197
|
-
return rewriteInterceptor(serverRes, req, res);
|
|
198
|
-
},
|
|
199
|
-
error(err, req, res) {
|
|
200
|
-
const errorMessage = `Proxy error: "${err.message}" when trying to "${req.method} ${req.url}"\n\n${err.stack}`;
|
|
201
|
-
logger.error(errorMessage);
|
|
202
|
-
if (res.writable) {
|
|
203
|
-
res.writeHead(500, {
|
|
204
|
-
'Content-Type': 'text/plain',
|
|
205
|
-
});
|
|
206
|
-
}
|
|
207
|
-
res.end(errorMessage);
|
|
208
|
-
},
|
|
209
|
-
},
|
|
210
|
-
});
|
|
211
|
-
}
|
|
212
|
-
|
|
213
|
-
class BaseAPI {
|
|
214
|
-
axios;
|
|
215
|
-
constructor(axios) {
|
|
216
|
-
this.axios = axios;
|
|
217
|
-
}
|
|
218
|
-
async checkAuth(headers) {
|
|
219
|
-
return this.axios
|
|
220
|
-
.get('/data/page/index/auth/info', {
|
|
221
|
-
headers: Object.assign({}, headers, { accept: 'text/html' }),
|
|
222
|
-
maxRedirects: 0,
|
|
223
|
-
})
|
|
224
|
-
.then(() => true)
|
|
225
|
-
.catch(() => false);
|
|
226
|
-
}
|
|
227
|
-
}
|
|
228
|
-
|
|
229
|
-
class AssetsAPI extends BaseAPI {
|
|
230
|
-
// Import for CJS and ESM
|
|
231
|
-
formdataModulePromise = import('formdata-node');
|
|
232
|
-
constructor(axios) {
|
|
233
|
-
super(axios);
|
|
234
|
-
}
|
|
235
|
-
getDownloadUrl(portalPageId) {
|
|
236
|
-
return `/admin/page/downloadassets/id/${portalPageId}`;
|
|
237
|
-
}
|
|
238
|
-
getDownloadTemplateUrl(templateId) {
|
|
239
|
-
return `/admin/pagetemplate/downloadassets/id/${templateId}`;
|
|
240
|
-
}
|
|
241
|
-
getUploadUrl(portalPageId) {
|
|
242
|
-
return `/admin/page/uploadassets/id/${portalPageId}`;
|
|
243
|
-
}
|
|
244
|
-
getUploadTemplateUrl(templateId) {
|
|
245
|
-
return `/admin/pagetemplate/uploadassets/id/${templateId}`;
|
|
246
|
-
}
|
|
247
|
-
async downloadPageAssets(portalPageId, headers) {
|
|
248
|
-
return this.axios
|
|
249
|
-
.get(this.getDownloadUrl(portalPageId), {
|
|
250
|
-
withCredentials: true,
|
|
251
|
-
headers: Object.assign({}, headers, { accept: '*/*' }),
|
|
252
|
-
responseType: 'arraybuffer',
|
|
253
|
-
})
|
|
254
|
-
.then((res) => res.data);
|
|
255
|
-
}
|
|
256
|
-
/**
|
|
257
|
-
* Upload page assets.
|
|
258
|
-
* @param portalPageId
|
|
259
|
-
* @param file - Zip file with assets
|
|
260
|
-
* @param headers
|
|
261
|
-
*/
|
|
262
|
-
async uploadPageAssets(portalPageId, file, headers) {
|
|
263
|
-
const formData = new (await this.formdataModulePromise).FormData();
|
|
264
|
-
const assetFile = new File([file.buffer], 'file.zip', { type: 'application/zip' });
|
|
265
|
-
formData.append('file', assetFile);
|
|
266
|
-
const url = this.getUploadUrl(portalPageId);
|
|
267
|
-
return this.axios
|
|
268
|
-
.post(url, formData, {
|
|
269
|
-
withCredentials: true,
|
|
270
|
-
headers: Object.assign({}, headers, {
|
|
271
|
-
accept: 'application/json',
|
|
272
|
-
'Content-Type': 'multipart/form-data',
|
|
273
|
-
Referer: this.axios.getUri({ url }),
|
|
274
|
-
}),
|
|
275
|
-
})
|
|
276
|
-
.then((res) => res.data);
|
|
277
|
-
}
|
|
278
|
-
async downloadTemplateAssets(templateId, headers) {
|
|
279
|
-
return this.axios
|
|
280
|
-
.get(this.getDownloadTemplateUrl(templateId), {
|
|
281
|
-
withCredentials: true,
|
|
282
|
-
headers: Object.assign({}, headers, { accept: '*/*' }),
|
|
283
|
-
responseType: 'arraybuffer',
|
|
284
|
-
})
|
|
285
|
-
.then((res) => res.data);
|
|
286
|
-
}
|
|
287
|
-
/**
|
|
288
|
-
* Upload template assets.
|
|
289
|
-
* @param templateId
|
|
290
|
-
* @param file - Zip file with assets
|
|
291
|
-
* @param headers
|
|
292
|
-
*/
|
|
293
|
-
async uploadTemplateAssets(templateId, file, headers) {
|
|
294
|
-
const formData = new (await this.formdataModulePromise).FormData();
|
|
295
|
-
const assetFile = new (await this.formdataModulePromise).File([file.buffer], 'file.zip', {
|
|
296
|
-
type: 'application/zip',
|
|
297
|
-
});
|
|
298
|
-
formData.append('file', assetFile, 'file.zip');
|
|
299
|
-
const url = this.getUploadTemplateUrl(templateId);
|
|
300
|
-
return this.axios
|
|
301
|
-
.post(url, formData, {
|
|
302
|
-
withCredentials: true,
|
|
303
|
-
headers: Object.assign({}, headers, {
|
|
304
|
-
accept: 'application/json',
|
|
305
|
-
'Content-Type': 'multipart/form-data',
|
|
306
|
-
Referer: this.axios.getUri({ url }),
|
|
307
|
-
}),
|
|
308
|
-
})
|
|
309
|
-
.then((res) => res.data);
|
|
310
|
-
}
|
|
311
|
-
}
|
|
312
|
-
class AssetsV7API extends AssetsAPI {
|
|
313
|
-
getDownloadUrl(portalPageId) {
|
|
314
|
-
return `/api/page/id/${portalPageId}/asset/download`;
|
|
315
|
-
}
|
|
316
|
-
getDownloadTemplateUrl(templateId) {
|
|
317
|
-
return `/api/page_template/id/${templateId}/asset/download`;
|
|
318
|
-
}
|
|
319
|
-
getUploadUrl(portalPageId) {
|
|
320
|
-
return `/api/page/id/${portalPageId}/asset/upload`;
|
|
321
|
-
}
|
|
322
|
-
getUploadTemplateUrl(templateId) {
|
|
323
|
-
return `/api/page_template/id/${templateId}/asset/upload`;
|
|
324
|
-
}
|
|
325
|
-
}
|
|
326
|
-
|
|
327
|
-
class PageAPI extends BaseAPI {
|
|
328
|
-
async getAll(headers) {
|
|
329
|
-
return (await this.axios.get('/api/page', {
|
|
330
|
-
withCredentials: true,
|
|
331
|
-
headers: Object.assign({}, headers, {
|
|
332
|
-
Accept: 'application/json',
|
|
333
|
-
'Content-Type': 'application/json',
|
|
334
|
-
'Cache-Control': 'no-cache',
|
|
335
|
-
Pragma: 'no-cache',
|
|
336
|
-
Expires: '0',
|
|
337
|
-
}),
|
|
338
|
-
})).data.pages;
|
|
339
|
-
}
|
|
340
|
-
async get(id, headers) {
|
|
341
|
-
return (await this.axios.get(`/api/page/id/${id}`, {
|
|
342
|
-
withCredentials: true,
|
|
343
|
-
headers: Object.assign({}, headers, {
|
|
344
|
-
accept: 'application/json',
|
|
345
|
-
'content-type': 'application/json',
|
|
346
|
-
}),
|
|
347
|
-
})).data.page;
|
|
348
|
-
}
|
|
349
|
-
async getPageContent(internalPageName, headers) {
|
|
350
|
-
return (await this.axios.get(`/p/${internalPageName}`, {
|
|
351
|
-
withCredentials: true,
|
|
352
|
-
headers: Object.assign({}, headers, {
|
|
353
|
-
accept: 'text/html',
|
|
354
|
-
'content-type': 'application/json',
|
|
355
|
-
}),
|
|
356
|
-
})).data;
|
|
357
|
-
}
|
|
358
|
-
async create(page, headers) {
|
|
359
|
-
return (await this.axios.post('/api/page', page, {
|
|
360
|
-
withCredentials: true,
|
|
361
|
-
headers: Object.assign({}, headers, {
|
|
362
|
-
accept: 'application/json',
|
|
363
|
-
'content-type': 'application/json',
|
|
364
|
-
}),
|
|
365
|
-
})).data.page;
|
|
366
|
-
}
|
|
367
|
-
}
|
|
368
|
-
|
|
369
|
-
class PageTemplateAPI extends BaseAPI {
|
|
370
|
-
async getAll(internal_name, headers) {
|
|
371
|
-
return (await this.axios.get(`/api/page_template`, {
|
|
372
|
-
withCredentials: true,
|
|
373
|
-
headers: Object.assign({}, headers, {
|
|
374
|
-
Accept: 'application/json',
|
|
375
|
-
'Content-Type': 'application/json',
|
|
376
|
-
'Cache-Control': 'no-cache',
|
|
377
|
-
Pragma: 'no-cache',
|
|
378
|
-
Expires: '0',
|
|
379
|
-
}),
|
|
380
|
-
params: {
|
|
381
|
-
internal_name,
|
|
382
|
-
},
|
|
383
|
-
})).data.page_templates;
|
|
384
|
-
}
|
|
385
|
-
async get(id, headers) {
|
|
386
|
-
return (await this.axios.get(`/api/page_template/id/${id}`, {
|
|
387
|
-
withCredentials: true,
|
|
388
|
-
headers: Object.assign({}, headers, {
|
|
389
|
-
accept: 'application/json',
|
|
390
|
-
'content-type': 'application/json',
|
|
391
|
-
}),
|
|
392
|
-
})).data.page_template;
|
|
393
|
-
}
|
|
394
|
-
}
|
|
395
|
-
|
|
396
|
-
const TEMPLATE_PAGE_NAME = '[DEV PAGE. DO NOT DELETE]';
|
|
397
|
-
class MiAPI {
|
|
398
|
-
#headers;
|
|
399
|
-
#axios;
|
|
400
|
-
#pageTemplate = null;
|
|
401
|
-
#pageTitle;
|
|
402
|
-
#pageVars;
|
|
403
|
-
#v7Features;
|
|
404
|
-
#isV710OrHigher;
|
|
405
|
-
#templateLoaded;
|
|
406
|
-
#templateLoadedResolve;
|
|
407
|
-
portalPageId;
|
|
408
|
-
templateLess;
|
|
409
|
-
assetsApi;
|
|
410
|
-
pageApi;
|
|
411
|
-
pageTemplateApi;
|
|
412
|
-
logger;
|
|
413
|
-
constructor(baseURL, opts) {
|
|
414
|
-
const { headers = {}, portalPageId, templateLess = true, disableSSLValidation = false, v7Features = false, } = opts || {};
|
|
415
|
-
this.#headers = headers;
|
|
416
|
-
this.#pageVars = [];
|
|
417
|
-
this.#pageTitle = '';
|
|
418
|
-
this.#v7Features = v7Features;
|
|
419
|
-
this.#isV710OrHigher = false;
|
|
420
|
-
this.#templateLoaded = Promise.resolve(false);
|
|
421
|
-
if (disableSSLValidation) {
|
|
422
|
-
axios.defaults.httpsAgent = new Agent({ rejectUnauthorized: false });
|
|
423
|
-
}
|
|
424
|
-
this.#axios = axios.create({
|
|
425
|
-
baseURL,
|
|
426
|
-
headers,
|
|
427
|
-
});
|
|
428
|
-
this.portalPageId = portalPageId;
|
|
429
|
-
this.templateLess = templateLess;
|
|
430
|
-
this.assetsApi = new (!v7Features ? AssetsAPI : AssetsV7API)(this.#axios);
|
|
431
|
-
this.pageApi = new PageAPI(this.#axios);
|
|
432
|
-
this.pageTemplateApi = new PageTemplateAPI(this.#axios);
|
|
433
|
-
this.logger = createLogger();
|
|
434
|
-
}
|
|
435
|
-
async isTemplateLoaded() {
|
|
436
|
-
return this.#templateLoaded;
|
|
437
|
-
}
|
|
438
|
-
get isV710OrHigher() {
|
|
439
|
-
return this.#isV710OrHigher;
|
|
440
|
-
}
|
|
441
|
-
#clearHeaders(headers) {
|
|
442
|
-
const obj = Object.assign({}, headers, { host: undefined, referer: undefined });
|
|
443
|
-
Object.keys(obj).forEach((key) => obj[key] === undefined && delete obj[key]);
|
|
444
|
-
this.#headers = obj;
|
|
445
|
-
return obj;
|
|
446
|
-
}
|
|
447
|
-
updateHeaders(headers) {
|
|
448
|
-
this.#clearHeaders(headers);
|
|
449
|
-
}
|
|
450
|
-
get localTemplateHTML() {
|
|
451
|
-
return /* HTML */ `<!DOCTYPE html>
|
|
452
|
-
<html lang="en">
|
|
453
|
-
<head>
|
|
454
|
-
<meta charset="UTF-8" />
|
|
455
|
-
<title>Local template</title>
|
|
456
|
-
<meta charset="UTF-8" />
|
|
457
|
-
<link rel="icon" type="image/svg+xml" href="/favicon.ico" />
|
|
458
|
-
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
|
|
459
|
-
</head>
|
|
460
|
-
<body>
|
|
461
|
-
<div id="mi-react-root"></div>
|
|
462
|
-
<script src="/auth/info.js"></script>
|
|
463
|
-
<script src="/js/main.js" defer></script>
|
|
464
|
-
<link rel="stylesheet" href="/css/main.css" />
|
|
465
|
-
</body>
|
|
466
|
-
</html>`;
|
|
467
|
-
}
|
|
468
|
-
/**
|
|
469
|
-
* Get page template
|
|
470
|
-
* @param headers
|
|
471
|
-
*/
|
|
472
|
-
async getPageTemplate(headers) {
|
|
473
|
-
if (!(await this.#templateLoaded) && !this.#pageTemplate) {
|
|
474
|
-
this.#templateLoaded = new Promise((resolve) => {
|
|
475
|
-
this.#templateLoadedResolve = resolve;
|
|
476
|
-
});
|
|
477
|
-
}
|
|
478
|
-
if (this.#pageTemplate) {
|
|
479
|
-
return Promise.resolve(this.#pageTemplate);
|
|
480
|
-
}
|
|
481
|
-
if (typeof this.templateLess === 'undefined') {
|
|
482
|
-
this.templateLess = false;
|
|
483
|
-
}
|
|
484
|
-
if (this.#v7Features) {
|
|
485
|
-
const page = await this.pageApi
|
|
486
|
-
.get(this.portalPageId, this.#clearHeaders(headers))
|
|
487
|
-
.then((response) => {
|
|
488
|
-
this.logger.info(colors.green('Page fetched'));
|
|
489
|
-
return response;
|
|
490
|
-
})
|
|
491
|
-
.catch(async (e) => {
|
|
492
|
-
this.#templateLoadedResolve(false);
|
|
493
|
-
if (await this.pageApi.checkAuth(this.#clearHeaders(headers))) {
|
|
494
|
-
this.logger.error(colors.red(`Error fetching page data: ${e.message}\n${e.stack}`));
|
|
495
|
-
throw new Error('Current user does not have access to the page');
|
|
496
|
-
}
|
|
497
|
-
else {
|
|
498
|
-
throw e;
|
|
499
|
-
}
|
|
500
|
-
});
|
|
501
|
-
if (typeof page.template_id !== 'undefined') {
|
|
502
|
-
this.#isV710OrHigher = true;
|
|
503
|
-
}
|
|
504
|
-
this.#pageTemplate = this.localTemplateHTML;
|
|
505
|
-
this.logger.info(colors.green('Local page template fetched'));
|
|
506
|
-
this.#templateLoadedResolve(true);
|
|
507
|
-
return this.#pageTemplate;
|
|
508
|
-
}
|
|
509
|
-
const pageList = await this.pageApi
|
|
510
|
-
.getAll(this.#clearHeaders(headers))
|
|
511
|
-
.then((response) => {
|
|
512
|
-
this.logger.info(colors.green('Page list fetched'));
|
|
513
|
-
return response;
|
|
514
|
-
})
|
|
515
|
-
.catch(async (e) => {
|
|
516
|
-
this.#templateLoadedResolve(false);
|
|
517
|
-
if (await this.pageApi.checkAuth(this.#clearHeaders(headers))) {
|
|
518
|
-
this.logger.error(colors.red(`Error fetching page list: ${e.message}\n${e.stack}`));
|
|
519
|
-
throw new Error('Current user does not have access to page list');
|
|
520
|
-
}
|
|
521
|
-
else {
|
|
522
|
-
throw e;
|
|
523
|
-
}
|
|
524
|
-
});
|
|
525
|
-
let page = pageList.find((p) => p.name === TEMPLATE_PAGE_NAME);
|
|
526
|
-
if (!page) {
|
|
527
|
-
this.logger.warn(colors.yellow('Creating dev page template...'));
|
|
528
|
-
page = await this.pageApi
|
|
529
|
-
.create({
|
|
530
|
-
enabled: 'Y',
|
|
531
|
-
name: TEMPLATE_PAGE_NAME,
|
|
532
|
-
internal_name: 'dev-page-template',
|
|
533
|
-
visible_in_homepage: 'Y',
|
|
534
|
-
}, this.#clearHeaders(headers))
|
|
535
|
-
.then((response) => {
|
|
536
|
-
this.logger.info(colors.green('Dev page created'));
|
|
537
|
-
return response;
|
|
538
|
-
})
|
|
539
|
-
.catch((e) => {
|
|
540
|
-
this.logger.error(colors.red(`Error creating dev page: ${e.message}`));
|
|
541
|
-
this.#templateLoadedResolve(false);
|
|
542
|
-
throw new Error(`Error when creating dev page.
|
|
543
|
-
That can be caused by missing permissions or page with name "${TEMPLATE_PAGE_NAME}" already exists`);
|
|
544
|
-
});
|
|
545
|
-
}
|
|
546
|
-
return await this.pageApi
|
|
547
|
-
.getPageContent(page.internal_name, this.#clearHeaders(headers))
|
|
548
|
-
.then((response) => {
|
|
549
|
-
this.#pageTemplate = response;
|
|
550
|
-
return response;
|
|
551
|
-
})
|
|
552
|
-
.then((response) => {
|
|
553
|
-
this.#templateLoadedResolve(true);
|
|
554
|
-
this.logger.info(colors.green('Page template fetched'));
|
|
555
|
-
return response;
|
|
556
|
-
})
|
|
557
|
-
.catch((e) => {
|
|
558
|
-
this.#templateLoadedResolve(false);
|
|
559
|
-
this.logger.error(colors.red(`Error fetching page template: ${e.message}`));
|
|
560
|
-
throw new Error('Error fetching page template');
|
|
561
|
-
});
|
|
562
|
-
}
|
|
563
|
-
/**
|
|
564
|
-
* Get page template variables
|
|
565
|
-
*
|
|
566
|
-
* @param pageId
|
|
567
|
-
* @param headers
|
|
568
|
-
*/
|
|
569
|
-
async getPageVariables(pageId, headers) {
|
|
570
|
-
this.#pageTemplate = await this.getPageTemplate(headers);
|
|
571
|
-
if (!this.portalPageId) {
|
|
572
|
-
this.portalPageId = pageId;
|
|
573
|
-
this.templateLess = false;
|
|
574
|
-
}
|
|
575
|
-
return await this.pageApi
|
|
576
|
-
.get(pageId, this.#clearHeaders(headers))
|
|
577
|
-
.then((response) => {
|
|
578
|
-
const { tags = '[]', name, template } = response;
|
|
579
|
-
if (template && tags) {
|
|
580
|
-
const parsed = JSON.parse(tags);
|
|
581
|
-
this.#pageVars = parsed;
|
|
582
|
-
this.#pageTitle = name;
|
|
583
|
-
return parsed;
|
|
584
|
-
}
|
|
585
|
-
this.#pageVars = [];
|
|
586
|
-
this.#pageTitle = name;
|
|
587
|
-
return [];
|
|
588
|
-
})
|
|
589
|
-
.catch((reason) => {
|
|
590
|
-
this.logger.error(colors.red(`Error fetching page variables: ${reason.message}`));
|
|
591
|
-
if (reason.response?.status === 404) {
|
|
592
|
-
throw new Error(`Portal Page with id "${pageId}" not found on instance ${this.#axios.getUri()}`);
|
|
593
|
-
}
|
|
594
|
-
if (reason.response?.status === 401) {
|
|
595
|
-
throw new Error(`Current user does not have access to page with id "${pageId}" on instance ${this.#axios.getUri()}`);
|
|
596
|
-
}
|
|
597
|
-
throw reason;
|
|
598
|
-
});
|
|
599
|
-
}
|
|
600
|
-
/**
|
|
601
|
-
* Build page with variables
|
|
602
|
-
*
|
|
603
|
-
* @param content
|
|
604
|
-
* @param miHudLess
|
|
605
|
-
*/
|
|
606
|
-
buildPage(content, miHudLess = false) {
|
|
607
|
-
let result = typeof content === 'string' ? content : content.toString('utf-8');
|
|
608
|
-
for (const v of this.#pageVars) {
|
|
609
|
-
result = result.replace(new RegExp(`\\[${v.name}\\]`, 'g'), v.value);
|
|
610
|
-
}
|
|
611
|
-
const dom = new JSDOM(miHudLess ? result : this.#pageTemplate);
|
|
612
|
-
const placeholderText = '%%PLACEHOLDER%%';
|
|
613
|
-
if (!miHudLess) {
|
|
614
|
-
const placeholder = dom.window.document.createElement('div');
|
|
615
|
-
placeholder.innerHTML = placeholderText;
|
|
616
|
-
const container = dom.window.document.querySelector('.main-side');
|
|
617
|
-
if (container) {
|
|
618
|
-
const scripts = container.querySelectorAll('script');
|
|
619
|
-
if (scripts.length) {
|
|
620
|
-
container.insertBefore(placeholder, scripts.item(scripts.length - 1));
|
|
621
|
-
}
|
|
622
|
-
else {
|
|
623
|
-
container.append(placeholder);
|
|
624
|
-
}
|
|
625
|
-
}
|
|
626
|
-
else {
|
|
627
|
-
const container = dom.window.document.createElement('div');
|
|
628
|
-
container.append(placeholder);
|
|
629
|
-
dom.window.document.body.append(container);
|
|
630
|
-
}
|
|
631
|
-
const head = dom.window.document.querySelector('head');
|
|
632
|
-
const title = head.querySelector('title');
|
|
633
|
-
if (title) {
|
|
634
|
-
title.text = this.#pageTitle;
|
|
635
|
-
}
|
|
636
|
-
else {
|
|
637
|
-
head.innerHTML += `<title>${this.#pageTitle}</title>`;
|
|
638
|
-
}
|
|
639
|
-
}
|
|
640
|
-
const serializedDom = dom.serialize();
|
|
641
|
-
return serializedDom.replace(new RegExp(`<div>\\s*${placeholderText}\\s*<\\/div>`, 'i'), result);
|
|
642
|
-
}
|
|
643
|
-
async getAssets() {
|
|
644
|
-
if (this.portalPageId) {
|
|
645
|
-
if (this.templateLess) {
|
|
646
|
-
return await this.assetsApi.downloadPageAssets(this.portalPageId, this.#headers);
|
|
647
|
-
}
|
|
648
|
-
else {
|
|
649
|
-
const pageInfo = await this.pageApi.get(this.portalPageId, this.#headers);
|
|
650
|
-
if (this.#isV710OrHigher) {
|
|
651
|
-
const templateInfo = await this.pageTemplateApi.get(pageInfo.template_id, this.#headers);
|
|
652
|
-
return await this.assetsApi.downloadTemplateAssets(templateInfo.id, this.#headers);
|
|
653
|
-
}
|
|
654
|
-
else {
|
|
655
|
-
if (pageInfo.template) {
|
|
656
|
-
return await this.assetsApi.downloadTemplateAssets(pageInfo.template, this.#headers);
|
|
657
|
-
}
|
|
658
|
-
}
|
|
659
|
-
}
|
|
660
|
-
}
|
|
661
|
-
}
|
|
662
|
-
async updateAssets(assets) {
|
|
663
|
-
if (this.portalPageId) {
|
|
664
|
-
if (this.templateLess) {
|
|
665
|
-
return await this.assetsApi.uploadPageAssets(this.portalPageId, assets, this.#headers);
|
|
666
|
-
}
|
|
667
|
-
else {
|
|
668
|
-
const pageInfo = await this.pageApi.get(this.portalPageId, this.#headers);
|
|
669
|
-
if (this.#isV710OrHigher) {
|
|
670
|
-
const templateInfo = await this.pageTemplateApi.get(pageInfo.template_id, this.#headers);
|
|
671
|
-
return await this.assetsApi.uploadTemplateAssets(templateInfo.id, assets, this.#headers);
|
|
672
|
-
}
|
|
673
|
-
else {
|
|
674
|
-
if (pageInfo.template) {
|
|
675
|
-
return await this.assetsApi.uploadTemplateAssets(pageInfo.template, assets, this.#headers);
|
|
676
|
-
}
|
|
677
|
-
}
|
|
678
|
-
}
|
|
679
|
-
}
|
|
680
|
-
}
|
|
681
|
-
}
|
|
682
|
-
|
|
683
|
-
class ClientService {
|
|
684
|
-
server;
|
|
685
|
-
opts;
|
|
686
|
-
eventMap;
|
|
687
|
-
logger;
|
|
688
|
-
constructor(server, opts) {
|
|
689
|
-
this.server = server;
|
|
690
|
-
this.opts = opts || {};
|
|
691
|
-
this.eventMap = new Map();
|
|
692
|
-
this.eventMap.set('info-data:request', this.onInfoDataRequest.bind(this));
|
|
693
|
-
this.eventMap.set('template:sync', this.onTemplateSync.bind(this));
|
|
694
|
-
this.logger = createLogger();
|
|
695
|
-
this.init();
|
|
696
|
-
}
|
|
697
|
-
init() {
|
|
698
|
-
const { ws } = this.server;
|
|
699
|
-
for (const [event, handler] of this.eventMap) {
|
|
700
|
-
ws.on(event, handler);
|
|
701
|
-
}
|
|
702
|
-
}
|
|
703
|
-
onInfoDataRequest() {
|
|
704
|
-
this.server.ws.send({
|
|
705
|
-
type: 'custom',
|
|
706
|
-
event: 'info-data:response',
|
|
707
|
-
data: {},
|
|
708
|
-
});
|
|
709
|
-
}
|
|
710
|
-
async onTemplateSync() {
|
|
711
|
-
if (this.opts.distService && this.opts.miAPI) {
|
|
712
|
-
const { distService, miAPI } = this.opts;
|
|
713
|
-
if (this.server.config.clientInjectionPlugin?.v7Features) {
|
|
714
|
-
if (!miAPI?.isV710OrHigher) {
|
|
715
|
-
this.server.ws.send('template:sync:response', {
|
|
716
|
-
error: 'This feature is available only for MI v7.1.0 or higher',
|
|
717
|
-
config: {
|
|
718
|
-
canSync: false,
|
|
719
|
-
},
|
|
720
|
-
});
|
|
721
|
-
return;
|
|
722
|
-
}
|
|
723
|
-
else {
|
|
724
|
-
this.server.ws.send('client:config:update', {
|
|
725
|
-
config: {
|
|
726
|
-
canSync: true,
|
|
727
|
-
},
|
|
728
|
-
});
|
|
729
|
-
}
|
|
730
|
-
}
|
|
731
|
-
const currentAssets = await miAPI?.getAssets();
|
|
732
|
-
const newAssets = currentAssets
|
|
733
|
-
? await distService?.saveBackupAndBuild(currentAssets)
|
|
734
|
-
: await distService?.buildNewAssets();
|
|
735
|
-
if (newAssets) {
|
|
736
|
-
const updateResult = await miAPI?.updateAssets(newAssets);
|
|
737
|
-
if (updateResult?.status === 'OK') {
|
|
738
|
-
const backupMeta = distService?.getBackupMeta();
|
|
739
|
-
const { lastBackupName: backupFilename, lastBackupHash: currentHash, lastBackupDate: backupDate, } = backupMeta || { lastBackupName: '', lastBackupHash: '', lastBackupDate: new Date().toISOString() };
|
|
740
|
-
this.server.ws.send('template:sync:response', {
|
|
741
|
-
syncedAt: new Date(backupDate),
|
|
742
|
-
currentHash,
|
|
743
|
-
backupFilename,
|
|
744
|
-
});
|
|
745
|
-
this.logger.info(colors.green('Template synced'));
|
|
746
|
-
}
|
|
747
|
-
else {
|
|
748
|
-
this.server.ws.send('template:sync:response', { error: 'Failed to update assets' });
|
|
749
|
-
this.logger.error(colors.red('Failed to update assets'));
|
|
750
|
-
}
|
|
751
|
-
}
|
|
752
|
-
else {
|
|
753
|
-
this.server.ws.send('template:sync:response', { error: 'Failed to build new assets' });
|
|
754
|
-
this.logger.error(colors.red('Failed to build new assets'));
|
|
755
|
-
return;
|
|
756
|
-
}
|
|
757
|
-
}
|
|
758
|
-
else {
|
|
759
|
-
this.server.ws.send('template:sync:response', { error: 'Dist service or MiAPI is not defined' });
|
|
760
|
-
this.logger.error(colors.red('Dist service or MiAPI is not defined'));
|
|
761
|
-
return;
|
|
762
|
-
}
|
|
763
|
-
}
|
|
764
|
-
}
|
|
765
|
-
|
|
766
|
-
const cache = new memoryCache.Cache();
|
|
767
|
-
const testCacheUrlRegExp = /\.[a-z0-9]+$/i;
|
|
768
|
-
function initProxyCache(opts) {
|
|
769
|
-
const { devServer, ttl = 10 * 60 * 1000 } = opts;
|
|
770
|
-
const logger = createLogger();
|
|
771
|
-
devServer.cache = cache;
|
|
772
|
-
return (req, res, next) => {
|
|
773
|
-
const url = req.originalUrl || req.url || '';
|
|
774
|
-
if (testCacheUrlRegExp.test(url.split('?')[0] || '')) {
|
|
775
|
-
const cacheItem = cache.get(url);
|
|
776
|
-
if (cacheItem) {
|
|
777
|
-
logger.info(`${colors.blue('Proxies request:')} ${colors.green(req.method)} ${url} -> ${colors.blue('Cache')} ${url}`);
|
|
778
|
-
for (const [header, value] of Object.entries(cacheItem.headers)) {
|
|
779
|
-
res.setHeader(header, value);
|
|
780
|
-
}
|
|
781
|
-
res.write(cacheItem.content);
|
|
782
|
-
res.end();
|
|
783
|
-
return;
|
|
784
|
-
}
|
|
785
|
-
const end = res.end;
|
|
786
|
-
const write = res.write;
|
|
787
|
-
let buffer = Buffer.from('', 'utf8');
|
|
788
|
-
// Rewrite response method and get the content.
|
|
789
|
-
res.write = function (data, encoding, callback) {
|
|
790
|
-
if (!res.hasHeader(PROXY_HEADER)) {
|
|
791
|
-
return write.call(this, data, encoding, callback);
|
|
792
|
-
}
|
|
793
|
-
buffer = Buffer.concat([buffer, data]);
|
|
794
|
-
return true;
|
|
795
|
-
};
|
|
796
|
-
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
|
797
|
-
// @ts-ignore
|
|
798
|
-
res.end = function (chunk, encoding, cb) {
|
|
799
|
-
if (!res.hasHeader(PROXY_HEADER)) {
|
|
800
|
-
return end.call(this, chunk, encoding, cb);
|
|
801
|
-
}
|
|
802
|
-
if (typeof chunk === 'string') {
|
|
803
|
-
buffer = Buffer.concat([buffer, Buffer.from(chunk, encoding)]);
|
|
804
|
-
}
|
|
805
|
-
if (Buffer.isBuffer(chunk)) {
|
|
806
|
-
buffer = Buffer.concat([buffer, chunk]);
|
|
807
|
-
}
|
|
808
|
-
if (res.hasHeader(PROXY_HEADER)) {
|
|
809
|
-
logger.info(`${colors.blue('[Cached]')} ${url}`);
|
|
810
|
-
cache.put(url, { headers: res.getHeaders(), content: buffer }, ttl);
|
|
811
|
-
}
|
|
812
|
-
end.call(this, buffer, encoding, cb);
|
|
813
|
-
};
|
|
814
|
-
}
|
|
815
|
-
next();
|
|
816
|
-
};
|
|
817
|
-
}
|
|
818
|
-
|
|
819
|
-
const TEMPLATE_PART_PAGE_NAME = 'pageName';
|
|
820
|
-
const TEMPLATE_PART_DATE = 'date';
|
|
821
|
-
const DIRNAME = path.dirname((typeof __filename !== 'undefined' && __filename) || fileURLToPath(import.meta.url));
|
|
822
|
-
const pluginPath = path.resolve(DIRNAME, '..', '..');
|
|
823
|
-
const node_modules_path = path.resolve(pluginPath, '..', '..');
|
|
824
|
-
const metaDirName = '.pp-dev-meta';
|
|
825
|
-
const metaDirPath = path.resolve(node_modules_path, metaDirName);
|
|
826
|
-
const metaFilePath = path.resolve(metaDirPath, 'sync-service.meta.json');
|
|
827
|
-
class DistService {
|
|
828
|
-
backupFolder;
|
|
829
|
-
backupNameTemplate;
|
|
830
|
-
dateFormat;
|
|
831
|
-
pageName;
|
|
832
|
-
currentMeta = null;
|
|
833
|
-
distZipFolder;
|
|
834
|
-
distZipFilename;
|
|
835
|
-
logger;
|
|
836
|
-
constructor(pageName, syncOptions) {
|
|
837
|
-
this.pageName = pageName;
|
|
838
|
-
const { backupFolder = path.resolve(process$1.cwd(), 'backups'), distZipFolder = path.resolve(process$1.cwd(), 'dist-zip'), distZipFilename = `${this.pageName}.zip`, backupNameTemplate = `{${TEMPLATE_PART_PAGE_NAME}}-{${TEMPLATE_PART_DATE}}.zip`, dateFormat = (date) => date.toISOString().replace(/:/g, '-').replace(/\..*$/, ''), } = syncOptions || {};
|
|
839
|
-
this.backupFolder = backupFolder;
|
|
840
|
-
this.backupNameTemplate = backupNameTemplate;
|
|
841
|
-
this.dateFormat = dateFormat;
|
|
842
|
-
this.distZipFolder = distZipFolder;
|
|
843
|
-
this.distZipFilename = distZipFilename;
|
|
844
|
-
this.syncMeta();
|
|
845
|
-
this.logger = createLogger();
|
|
846
|
-
}
|
|
847
|
-
async checkMeta() {
|
|
848
|
-
try {
|
|
849
|
-
await promises.stat(metaDirPath);
|
|
850
|
-
}
|
|
851
|
-
catch {
|
|
852
|
-
await promises.mkdir(metaDirPath);
|
|
853
|
-
}
|
|
854
|
-
try {
|
|
855
|
-
await promises.stat(this.backupFolder);
|
|
856
|
-
}
|
|
857
|
-
catch {
|
|
858
|
-
await promises.mkdir(this.backupFolder);
|
|
859
|
-
}
|
|
860
|
-
}
|
|
861
|
-
async readMetaFile() {
|
|
862
|
-
await this.checkMeta();
|
|
863
|
-
return await promises
|
|
864
|
-
.readFile(metaFilePath, {
|
|
865
|
-
encoding: 'utf-8',
|
|
866
|
-
})
|
|
867
|
-
.catch(() => '{}');
|
|
868
|
-
}
|
|
869
|
-
async writeMetaFile(meta) {
|
|
870
|
-
await this.checkMeta();
|
|
871
|
-
return await promises.writeFile(metaFilePath, JSON.stringify(meta, null, 2), {
|
|
872
|
-
encoding: 'utf-8',
|
|
873
|
-
});
|
|
874
|
-
}
|
|
875
|
-
async syncMeta() {
|
|
876
|
-
if (!this.currentMeta) {
|
|
877
|
-
this.currentMeta = JSON.parse(await this.readMetaFile());
|
|
878
|
-
}
|
|
879
|
-
else {
|
|
880
|
-
await this.writeMetaFile(this.currentMeta);
|
|
881
|
-
}
|
|
882
|
-
}
|
|
883
|
-
async getLatestSavedBackup() {
|
|
884
|
-
const { lastBackupName } = this.currentMeta;
|
|
885
|
-
if (!lastBackupName) {
|
|
886
|
-
return null;
|
|
887
|
-
}
|
|
888
|
-
const backupPath = path.resolve(this.backupFolder, lastBackupName);
|
|
889
|
-
try {
|
|
890
|
-
await promises.stat(backupPath);
|
|
891
|
-
return backupPath;
|
|
892
|
-
}
|
|
893
|
-
catch {
|
|
894
|
-
return null;
|
|
895
|
-
}
|
|
896
|
-
}
|
|
897
|
-
backupName(pageName, date = new Date()) {
|
|
898
|
-
return this.backupNameTemplate
|
|
899
|
-
.replace(`{${TEMPLATE_PART_PAGE_NAME}}`, pageName)
|
|
900
|
-
.replace(`{${TEMPLATE_PART_DATE}}`, this.dateFormat(date));
|
|
901
|
-
}
|
|
902
|
-
getBackupMeta() {
|
|
903
|
-
return this.currentMeta;
|
|
904
|
-
}
|
|
905
|
-
async saveBackup(backupFile) {
|
|
906
|
-
const backupFileHash = crypto.createHash('md5').update(backupFile).digest('hex');
|
|
907
|
-
const lastSavedBackup = await this.getLatestSavedBackup();
|
|
908
|
-
if (lastSavedBackup) {
|
|
909
|
-
const { lastBackupHash } = this.currentMeta;
|
|
910
|
-
if (lastBackupHash === backupFileHash) {
|
|
911
|
-
return;
|
|
912
|
-
}
|
|
913
|
-
}
|
|
914
|
-
const backupDate = new Date();
|
|
915
|
-
const filename = this.backupName(this.pageName, backupDate);
|
|
916
|
-
this.currentMeta.lastBackupName = filename;
|
|
917
|
-
this.currentMeta.lastBackupHash = backupFileHash;
|
|
918
|
-
this.currentMeta.lastBackupDate = backupDate.toISOString();
|
|
919
|
-
await this.syncMeta();
|
|
920
|
-
return await promises.writeFile(path.resolve(this.backupFolder, filename), backupFile).finally(() => {
|
|
921
|
-
this.logger.info(`Backup saved to ${filename}`);
|
|
922
|
-
});
|
|
923
|
-
}
|
|
924
|
-
async buildNewAssets() {
|
|
925
|
-
const buildCommand = new Promise((resolve, reject) => {
|
|
926
|
-
let data = '';
|
|
927
|
-
// Colorized log output with message about build start
|
|
928
|
-
this.logger.info(colors.cyan('[DistService] Build started'));
|
|
929
|
-
const proc = child_process.spawn('node', [path.resolve(pluginPath, './bin/pp-dev.js'), 'build'], {
|
|
930
|
-
cwd: process$1.cwd(),
|
|
931
|
-
env: Object.assign({}, process$1.env, { NODE_ENV: 'production' }),
|
|
932
|
-
stdio: 'inherit',
|
|
933
|
-
});
|
|
934
|
-
proc.on('message', (msg) => {
|
|
935
|
-
data += msg;
|
|
936
|
-
});
|
|
937
|
-
proc.on('close', (code) => {
|
|
938
|
-
if (code !== 0) {
|
|
939
|
-
reject(new Error(`build command exited with code ${code}`));
|
|
940
|
-
return;
|
|
941
|
-
}
|
|
942
|
-
resolve(data);
|
|
943
|
-
});
|
|
944
|
-
proc.on('error', (err) => {
|
|
945
|
-
reject(err);
|
|
946
|
-
});
|
|
947
|
-
});
|
|
948
|
-
try {
|
|
949
|
-
await buildCommand.finally(() => {
|
|
950
|
-
// Colorized log output with message about build end
|
|
951
|
-
this.logger.info(colors.cyan('[DistService] Build finished'));
|
|
952
|
-
});
|
|
953
|
-
const assetFile = path.resolve(process$1.cwd(), this.distZipFolder, this.distZipFilename);
|
|
954
|
-
if (!(await promises.stat(assetFile))) {
|
|
955
|
-
throw new Error(`File ${assetFile} not found`);
|
|
956
|
-
}
|
|
957
|
-
return await promises.readFile(assetFile);
|
|
958
|
-
}
|
|
959
|
-
catch (e) {
|
|
960
|
-
console.log(e);
|
|
961
|
-
throw e;
|
|
962
|
-
}
|
|
963
|
-
}
|
|
964
|
-
async saveBackupAndBuild(backupFile) {
|
|
965
|
-
await this.saveBackup(backupFile);
|
|
966
|
-
return await this.buildNewAssets();
|
|
967
|
-
}
|
|
968
|
-
}
|
|
969
|
-
|
|
970
|
-
function decodeContent(content, contentEncoding) {
|
|
971
|
-
switch (contentEncoding) {
|
|
972
|
-
case 'gzip':
|
|
973
|
-
return unzipSync(content);
|
|
974
|
-
case 'br':
|
|
975
|
-
return brotliDecompressSync(content);
|
|
976
|
-
case 'deflate':
|
|
977
|
-
return deflateSync(content);
|
|
978
|
-
default:
|
|
979
|
-
return content;
|
|
980
|
-
}
|
|
981
|
-
}
|
|
982
|
-
function encodeContent(content, contentEncoding) {
|
|
983
|
-
switch (contentEncoding) {
|
|
984
|
-
case 'gzip':
|
|
985
|
-
return gzipSync(content);
|
|
986
|
-
case 'br':
|
|
987
|
-
return brotliCompressSync(content);
|
|
988
|
-
case 'deflate':
|
|
989
|
-
return inflateSync(content);
|
|
990
|
-
default:
|
|
991
|
-
return content;
|
|
992
|
-
}
|
|
993
|
-
}
|
|
994
|
-
|
|
995
|
-
/**
|
|
996
|
-
* Rewrite response middleware
|
|
997
|
-
*
|
|
998
|
-
* @param predicate Check if need to rewrite response data
|
|
999
|
-
* @param rewrite Rewrite response content handler
|
|
1000
|
-
*/
|
|
1001
|
-
function initRewriteResponse(predicate, rewrite) {
|
|
1002
|
-
return async (req, res, next) => {
|
|
1003
|
-
if (await predicate(req.url ?? '', req, res)) {
|
|
1004
|
-
const logger = createLogger();
|
|
1005
|
-
logger.info(`Rewrite response for ${req.url}`);
|
|
1006
|
-
const end = res.end;
|
|
1007
|
-
const buffers = [];
|
|
1008
|
-
res.write = function (body) {
|
|
1009
|
-
buffers.push(body);
|
|
1010
|
-
return true;
|
|
1011
|
-
};
|
|
1012
|
-
res.end = function (chunk, encoding, cb) {
|
|
1013
|
-
if (typeof chunk === 'string') {
|
|
1014
|
-
buffers.push(Buffer.from(chunk));
|
|
1015
|
-
}
|
|
1016
|
-
const contentEncoding = res.getHeader('content-encoding');
|
|
1017
|
-
const content = decodeContent(Buffer.from(Buffer.concat(buffers)), contentEncoding);
|
|
1018
|
-
const bufferEncoding = typeof encoding !== 'function' && encoding ? encoding : 'utf-8';
|
|
1019
|
-
const endCallback = typeof encoding === 'function' ? encoding : cb;
|
|
1020
|
-
end.call(this, encodeContent(rewrite(content, req, res), contentEncoding), bufferEncoding, endCallback);
|
|
1021
|
-
return this;
|
|
1022
|
-
};
|
|
1023
|
-
}
|
|
1024
|
-
next();
|
|
1025
|
-
};
|
|
1026
|
-
}
|
|
1027
|
-
|
|
1028
|
-
function initPPRedirect(base, templateName) {
|
|
1029
|
-
base = base.startsWith('/') ? base : `/${base}`;
|
|
1030
|
-
base = base.endsWith('/') ? base : `${base}/`;
|
|
1031
|
-
const baseWithoutTrailingSlash = base.endsWith('/') ? base.slice(0, -1) : base;
|
|
1032
|
-
const logger = createLogger();
|
|
1033
|
-
return (req, res, next) => {
|
|
1034
|
-
const parsedUrl = new URL$1(req.url ?? '', 'http://localhost');
|
|
1035
|
-
const { pathname, search } = parsedUrl;
|
|
1036
|
-
const findPaths = ['/', baseWithoutTrailingSlash];
|
|
1037
|
-
if (templateName) {
|
|
1038
|
-
findPaths.push(`/pt/${templateName}`);
|
|
1039
|
-
findPaths.push(`/pl/${templateName}`);
|
|
1040
|
-
}
|
|
1041
|
-
// Redirect from `/` and `/pt/${templateName}` and `${base}` (without a training slash) to portal page address
|
|
1042
|
-
if (findPaths.includes(pathname)) {
|
|
1043
|
-
const redirectUrl = `${base}${search}`;
|
|
1044
|
-
logger.info(colors.yellow(`Redirecting to: ${redirectUrl}`));
|
|
1045
|
-
return redirect(res, redirectUrl, 302);
|
|
1046
|
-
}
|
|
1047
|
-
next();
|
|
1048
|
-
};
|
|
1049
|
-
}
|
|
1050
|
-
|
|
1051
|
-
function initLoadPPData(applyUrlRegExp, mi, opts) {
|
|
1052
|
-
const { templateLess = false, miHudLess = false, portalPageId } = opts;
|
|
1053
|
-
const logger = createLogger();
|
|
1054
|
-
return (req, res, next) => {
|
|
1055
|
-
const isNeedTemplateLoad = !(templateLess && miHudLess);
|
|
1056
|
-
const isApplyRequest = applyUrlRegExp.test(cutUrlParams(req.url ?? ''));
|
|
1057
|
-
if (isNeedTemplateLoad && isApplyRequest) {
|
|
1058
|
-
const headers = (req.headers ?? {});
|
|
1059
|
-
logger.info(colors.green(`Start loading page data`));
|
|
1060
|
-
const loadPageData = !templateLess && typeof portalPageId !== 'undefined'
|
|
1061
|
-
? mi.getPageVariables(portalPageId, headers)
|
|
1062
|
-
: mi.getPageTemplate(headers);
|
|
1063
|
-
loadPageData
|
|
1064
|
-
.then(() => {
|
|
1065
|
-
next();
|
|
1066
|
-
})
|
|
1067
|
-
.catch((reason) => {
|
|
1068
|
-
if (reason.response) {
|
|
1069
|
-
logger.info(colors.red('Page data loading failed. Not authorized'));
|
|
1070
|
-
const redirectUrl = `/home?proxyRedirect=${encodeURIComponent('/')}`;
|
|
1071
|
-
logger.info(colors.yellow(`Redirecting to: ${redirectUrl}`));
|
|
1072
|
-
return redirect(res, redirectUrl, 302);
|
|
1073
|
-
}
|
|
1074
|
-
logger.info(colors.red(`Page data loading failed. Error: ${reason.message}`));
|
|
1075
|
-
next(reason);
|
|
1076
|
-
});
|
|
1077
|
-
}
|
|
1078
|
-
else {
|
|
1079
|
-
next();
|
|
1080
|
-
}
|
|
1081
|
-
};
|
|
1082
|
-
}
|
|
1083
|
-
|
|
1084
|
-
function isVitePPDevOptions(options) {
|
|
1085
|
-
return (typeof options === 'object' &&
|
|
1086
|
-
typeof options.templateName === 'string' &&
|
|
1087
|
-
(typeof options.backendBaseURL === 'string' || options.backendBaseURL === undefined) &&
|
|
1088
|
-
(typeof options.portalPageId === 'number' || options.portalPageId === undefined) &&
|
|
1089
|
-
(typeof options.templateLess === 'boolean' || options.templateLess === undefined) &&
|
|
1090
|
-
(typeof options.miHudLess === 'boolean' || options.miHudLess === undefined) &&
|
|
1091
|
-
(typeof options.enableProxyCache === 'boolean' || options.enableProxyCache === undefined) &&
|
|
1092
|
-
(typeof options.proxyCacheTTL === 'number' || options.proxyCacheTTL === undefined) &&
|
|
1093
|
-
(typeof options.disableSSLValidation === 'boolean' || options.disableSSLValidation === undefined) &&
|
|
1094
|
-
(typeof options.imageOptimizer === 'boolean' ||
|
|
1095
|
-
typeof options.imageOptimizer === 'object' ||
|
|
1096
|
-
options.imageOptimizer === undefined) &&
|
|
1097
|
-
(typeof options.outDir === 'string' || options.outDir === undefined) &&
|
|
1098
|
-
(typeof options.distZip === 'boolean' || typeof options.distZip === 'object' || options.distZip === undefined) &&
|
|
1099
|
-
(typeof options.syncBackupsDir === 'string' || options.syncBackupsDir === undefined) &&
|
|
1100
|
-
(typeof options.v7Features === 'boolean' || options.v7Features === undefined));
|
|
1101
|
-
}
|
|
1102
|
-
function throwConfigError(config) {
|
|
1103
|
-
if (typeof config !== 'object') {
|
|
1104
|
-
throw new Error('VitePPDevOptions must be an object');
|
|
1105
|
-
}
|
|
1106
|
-
if (typeof config.templateName !== 'string') {
|
|
1107
|
-
throw new Error('VitePPDevOptions.templateName must be a string');
|
|
1108
|
-
}
|
|
1109
|
-
if (config.backendBaseURL !== undefined && typeof config.backendBaseURL !== 'string') {
|
|
1110
|
-
throw new Error('VitePPDevOptions.backendBaseURL must be a string');
|
|
1111
|
-
}
|
|
1112
|
-
if (config.portalPageId !== undefined && typeof config.portalPageId !== 'number') {
|
|
1113
|
-
throw new Error('VitePPDevOptions.portalPageId must be a number');
|
|
1114
|
-
}
|
|
1115
|
-
if (config.templateLess !== undefined && typeof config.templateLess !== 'boolean') {
|
|
1116
|
-
throw new Error('VitePPDevOptions.templateLess must be a boolean');
|
|
1117
|
-
}
|
|
1118
|
-
if (config.miHudLess !== undefined && typeof config.miHudLess !== 'boolean') {
|
|
1119
|
-
throw new Error('VitePPDevOptions.miHudLess must be a boolean');
|
|
1120
|
-
}
|
|
1121
|
-
if (config.enableProxyCache !== undefined && typeof config.enableProxyCache !== 'boolean') {
|
|
1122
|
-
throw new Error('VitePPDevOptions.enableProxyCache must be a boolean');
|
|
1123
|
-
}
|
|
1124
|
-
if (config.proxyCacheTTL !== undefined && typeof config.proxyCacheTTL !== 'number') {
|
|
1125
|
-
throw new Error('VitePPDevOptions.proxyCacheTTL must be a number');
|
|
1126
|
-
}
|
|
1127
|
-
if (config.disableSSLValidation !== undefined && typeof config.disableSSLValidation !== 'boolean') {
|
|
1128
|
-
throw new Error('VitePPDevOptions.disableSSLValidation must be a boolean');
|
|
1129
|
-
}
|
|
1130
|
-
if (config.imageOptimizer !== undefined &&
|
|
1131
|
-
typeof config.imageOptimizer !== 'boolean' &&
|
|
1132
|
-
typeof config.imageOptimizer !== 'object') {
|
|
1133
|
-
throw new Error('VitePPDevOptions.imageOptimizer must be a boolean or an object');
|
|
1134
|
-
}
|
|
1135
|
-
if (config.outDir !== undefined && typeof config.outDir !== 'string') {
|
|
1136
|
-
throw new Error('VitePPDevOptions.outDir must be a string');
|
|
1137
|
-
}
|
|
1138
|
-
if (config.distZip !== undefined && typeof config.distZip !== 'boolean' && typeof config.distZip !== 'object') {
|
|
1139
|
-
throw new Error('VitePPDevOptions.distZip must be a boolean or an object');
|
|
1140
|
-
}
|
|
1141
|
-
if (config.syncBackupsDir !== undefined && typeof config.syncBackupsDir !== 'string') {
|
|
1142
|
-
throw new Error('VitePPDevOptions.syncBackupsDir must be a string');
|
|
1143
|
-
}
|
|
1144
|
-
if (config.v7Features !== undefined && typeof config.v7Features !== 'boolean') {
|
|
1145
|
-
throw new Error('VitePPDevOptions.v7Features must be a boolean');
|
|
1146
|
-
}
|
|
1147
|
-
}
|
|
1148
|
-
function normalizeVitePPDevConfig(config) {
|
|
1149
|
-
!isVitePPDevOptions(config) && throwConfigError(config);
|
|
1150
|
-
const { enableProxyCache = true, proxyCacheTTL = 10 * 60 * 1000, disableSSLValidation = false, imageOptimizer = true, miHudLess = false, templateLess = false, outDir = 'dist', distZip = true, syncBackupsDir = 'backups', v7Features = false, } = config || {};
|
|
1151
|
-
let distZipConfig = distZip;
|
|
1152
|
-
if (distZipConfig === true) {
|
|
1153
|
-
distZipConfig = {
|
|
1154
|
-
outFileName: `${config.templateName}.zip`,
|
|
1155
|
-
outDir: 'dist-zip',
|
|
1156
|
-
};
|
|
1157
|
-
}
|
|
1158
|
-
else if (typeof distZip === 'object') {
|
|
1159
|
-
distZipConfig = {
|
|
1160
|
-
outFileName: typeof distZip.outFileName === 'string'
|
|
1161
|
-
? distZip.outFileName.replace('[templateName]', config.templateName)
|
|
1162
|
-
: `${config.templateName}.zip`,
|
|
1163
|
-
outDir: distZip.outDir ?? 'dist-zip',
|
|
1164
|
-
};
|
|
1165
|
-
}
|
|
1166
|
-
else {
|
|
1167
|
-
distZipConfig = false;
|
|
1168
|
-
}
|
|
1169
|
-
let imageOptimizerConfig = imageOptimizer;
|
|
1170
|
-
if (typeof imageOptimizer === 'boolean') {
|
|
1171
|
-
if (imageOptimizerConfig === true) {
|
|
1172
|
-
imageOptimizerConfig = {};
|
|
1173
|
-
}
|
|
1174
|
-
}
|
|
1175
|
-
else if (typeof imageOptimizer !== 'object') {
|
|
1176
|
-
imageOptimizerConfig = false;
|
|
1177
|
-
}
|
|
1178
|
-
return {
|
|
1179
|
-
enableProxyCache,
|
|
1180
|
-
proxyCacheTTL,
|
|
1181
|
-
disableSSLValidation,
|
|
1182
|
-
imageOptimizer: imageOptimizerConfig,
|
|
1183
|
-
templateLess,
|
|
1184
|
-
miHudLess,
|
|
1185
|
-
outDir,
|
|
1186
|
-
distZip: distZipConfig,
|
|
1187
|
-
syncBackupsDir,
|
|
1188
|
-
v7Features,
|
|
1189
|
-
...config,
|
|
1190
|
-
};
|
|
1191
|
-
}
|
|
1192
|
-
function vitePPDev(options) {
|
|
1193
|
-
const { templateName, templateLess, backendBaseURL, miHudLess, portalPageId, enableProxyCache, proxyCacheTTL, disableSSLValidation, distZip, syncBackupsDir, v7Features, } = options || {};
|
|
1194
|
-
// Avoid server caching for index.html file when first loading
|
|
1195
|
-
let isFirstRequest = true;
|
|
1196
|
-
process.cwd();
|
|
1197
|
-
return {
|
|
1198
|
-
name: 'vite-pp-dev',
|
|
1199
|
-
apply: 'serve',
|
|
1200
|
-
config: (config) => {
|
|
1201
|
-
config.clientInjectionPlugin = { backendBaseURL, portalPageId, templateLess, v7Features };
|
|
1202
|
-
if (v7Features) {
|
|
1203
|
-
config.base = `/pl/${templateName}`;
|
|
1204
|
-
}
|
|
1205
|
-
if (config.root) {
|
|
1206
|
-
config.root;
|
|
1207
|
-
}
|
|
1208
|
-
return config;
|
|
1209
|
-
},
|
|
1210
|
-
transformIndexHtml: async (html, ctx) => {
|
|
1211
|
-
const result = { html, tags: [] };
|
|
1212
|
-
if (isFirstRequest) {
|
|
1213
|
-
isFirstRequest = false;
|
|
1214
|
-
result.tags.push({
|
|
1215
|
-
tag: 'script',
|
|
1216
|
-
injectTo: 'body',
|
|
1217
|
-
children: `${Math.random()}`,
|
|
1218
|
-
});
|
|
1219
|
-
}
|
|
1220
|
-
return result;
|
|
1221
|
-
},
|
|
1222
|
-
configureServer: (server) => {
|
|
1223
|
-
let base = server.config.base;
|
|
1224
|
-
if (!base.endsWith('/')) {
|
|
1225
|
-
base += '/';
|
|
1226
|
-
}
|
|
1227
|
-
const baseWithoutTrailingSlash = base.substring(0, base.lastIndexOf('/'));
|
|
1228
|
-
server.middlewares.use(initPPRedirect(base, templateName));
|
|
1229
|
-
if (backendBaseURL) {
|
|
1230
|
-
const baseUrlHost = new URL(backendBaseURL).host;
|
|
1231
|
-
const mi = new MiAPI(backendBaseURL, {
|
|
1232
|
-
headers: {
|
|
1233
|
-
host: baseUrlHost,
|
|
1234
|
-
referer: backendBaseURL,
|
|
1235
|
-
origin: backendBaseURL.replace(/^(https?:\/\/)([^/]+)(\/.*)?$/i, '$1$2'),
|
|
1236
|
-
},
|
|
1237
|
-
portalPageId,
|
|
1238
|
-
templateLess,
|
|
1239
|
-
disableSSLValidation,
|
|
1240
|
-
v7Features,
|
|
1241
|
-
});
|
|
1242
|
-
if (enableProxyCache) {
|
|
1243
|
-
let ttl = +proxyCacheTTL;
|
|
1244
|
-
if (!ttl || Number.isNaN(ttl) || ttl < 0) {
|
|
1245
|
-
ttl = 10 * 60 * 1000; // 10 minutes
|
|
1246
|
-
}
|
|
1247
|
-
server.middlewares.use(initProxyCache({ devServer: server, ttl }));
|
|
1248
|
-
}
|
|
1249
|
-
server.middlewares.use(initProxy({
|
|
1250
|
-
devServer: server,
|
|
1251
|
-
baseURL: backendBaseURL,
|
|
1252
|
-
proxyIgnore: ['/@vite', '/@metricinsights', '/@', baseWithoutTrailingSlash],
|
|
1253
|
-
disableSSLValidation,
|
|
1254
|
-
}));
|
|
1255
|
-
const isIndexRegExp = new RegExp(`^((${base})|/)$`);
|
|
1256
|
-
// Get portal page variables from the backend (also, redirect magic)
|
|
1257
|
-
server.middlewares.use(initLoadPPData(isIndexRegExp, mi, options));
|
|
1258
|
-
const distService = distZip !== false
|
|
1259
|
-
? new DistService(templateName, Object.assign({ backupDir: syncBackupsDir }, typeof distZip === 'object'
|
|
1260
|
-
? { distZipFolder: distZip.outDir, distZipFilename: distZip.outFileName }
|
|
1261
|
-
: undefined))
|
|
1262
|
-
: undefined;
|
|
1263
|
-
new ClientService(server, { distService, miAPI: mi });
|
|
1264
|
-
return () => {
|
|
1265
|
-
server.middlewares.use(initRewriteResponse((url) => {
|
|
1266
|
-
return url.endsWith('index.html');
|
|
1267
|
-
}, (response, req) => {
|
|
1268
|
-
return Buffer.from(urlReplacer(baseUrlHost, req.headers.host ?? '', mi.buildPage(response, miHudLess)));
|
|
1269
|
-
}));
|
|
1270
|
-
};
|
|
1271
|
-
}
|
|
1272
|
-
},
|
|
1273
|
-
};
|
|
1274
|
-
}
|
|
1275
|
-
|
|
1276
|
-
export { MiAPI as M, colors as a, initProxyCache as b, createLogger as c, initProxy as d, initLoadPPData as e, initRewriteResponse as f, cutUrlParams as g, initPPRedirect as i, normalizeVitePPDevConfig as n, urlReplacer as u, vitePPDev as v };
|
|
1277
|
-
//# sourceMappingURL=plugin-BeHiwpzF.js.map
|