@tourmind-frontend/monitor-plugin-nuxt 1.3.0 → 1.4.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/dist/index.cjs +27 -6
- package/dist/index.d.ts +12 -3
- package/package.json +3 -3
- package/templates/plugin.client.js +1 -1
package/dist/index.cjs
CHANGED
|
@@ -82,7 +82,8 @@ function readSourceContext(rootDir, file, hintLine, hintCol, contextLines = 10)
|
|
|
82
82
|
}
|
|
83
83
|
function MonitorModule(options) {
|
|
84
84
|
if (!options.url) throw new Error(`${LOG_PREFIX} "url" is required`);
|
|
85
|
-
if (!options.
|
|
85
|
+
if (!options.clientKey) throw new Error(`${LOG_PREFIX} "clientKey" is required`);
|
|
86
|
+
if (!options.authToken) throw new Error(`${LOG_PREFIX} "authToken" is required`);
|
|
86
87
|
if (!options.commit) throw new Error(`${LOG_PREFIX} "commit" is required`);
|
|
87
88
|
this.extendBuild((config, { isClient, isDev }) => {
|
|
88
89
|
if (isDev || !isClient) return;
|
|
@@ -91,7 +92,7 @@ function MonitorModule(options) {
|
|
|
91
92
|
config.plugins.push(
|
|
92
93
|
new import_monitor_plugin_webpack.default({
|
|
93
94
|
url: options.url,
|
|
94
|
-
|
|
95
|
+
authToken: options.authToken,
|
|
95
96
|
commit: options.commit
|
|
96
97
|
})
|
|
97
98
|
);
|
|
@@ -102,14 +103,17 @@ function MonitorModule(options) {
|
|
|
102
103
|
mode: "client",
|
|
103
104
|
options: {
|
|
104
105
|
url: options.url,
|
|
105
|
-
|
|
106
|
+
clientKey: options.clientKey
|
|
106
107
|
}
|
|
107
108
|
});
|
|
108
109
|
const ssrReportUrl = `${options.url.replace(/\/+$/, "")}/api/ssr-report`;
|
|
109
|
-
const
|
|
110
|
+
const clientKey = options.clientKey;
|
|
111
|
+
const commit = options.commit;
|
|
112
|
+
const publicUrlBase = (options.publicUrl || "").replace(/\/+$/, "") || null;
|
|
110
113
|
const rootDir = this.options.rootDir || this.options.srcDir || process.cwd();
|
|
111
114
|
this.nuxt.hook("render:errorMiddleware", (app) => {
|
|
112
115
|
app.use((err, req, _res, next) => {
|
|
116
|
+
var _a;
|
|
113
117
|
if (typeof fetch === "function") {
|
|
114
118
|
try {
|
|
115
119
|
const e = err;
|
|
@@ -120,13 +124,30 @@ function MonitorModule(options) {
|
|
|
120
124
|
new RegExp(`(${frame.file.replace(/[.*+?^${}()|[\]\\]/g, "\\$&")}:)${frame.line}(:)`),
|
|
121
125
|
`$1${sourceCtx.line}$2`
|
|
122
126
|
) : stack;
|
|
127
|
+
const path = req.url || "";
|
|
128
|
+
let fullUrl = path;
|
|
129
|
+
if (publicUrlBase) {
|
|
130
|
+
fullUrl = `${publicUrlBase}${path.startsWith("/") ? path : `/${path}`}`;
|
|
131
|
+
} else {
|
|
132
|
+
const headers = req && req.headers || {};
|
|
133
|
+
const headerValue = (key) => {
|
|
134
|
+
const v = headers[key];
|
|
135
|
+
return Array.isArray(v) ? v[0] : v;
|
|
136
|
+
};
|
|
137
|
+
const host = headerValue("x-forwarded-host") || headerValue("host");
|
|
138
|
+
if (host) {
|
|
139
|
+
const proto = headerValue("x-forwarded-proto") || (((_a = req.connection) == null ? void 0 : _a.encrypted) ? "https" : "http");
|
|
140
|
+
fullUrl = `${proto}://${host}${path.startsWith("/") ? path : `/${path}`}`;
|
|
141
|
+
}
|
|
142
|
+
}
|
|
123
143
|
fetch(ssrReportUrl, {
|
|
124
144
|
method: "POST",
|
|
125
145
|
headers: { "Content-Type": "application/json" },
|
|
126
146
|
body: JSON.stringify({
|
|
127
|
-
token,
|
|
147
|
+
token: clientKey,
|
|
128
148
|
stack: refinedStack,
|
|
129
|
-
url:
|
|
149
|
+
url: fullUrl,
|
|
150
|
+
commit,
|
|
130
151
|
...sourceCtx || {}
|
|
131
152
|
})
|
|
132
153
|
}).catch(() => {
|
package/dist/index.d.ts
CHANGED
|
@@ -1,10 +1,18 @@
|
|
|
1
1
|
export interface MonitorModuleOptions {
|
|
2
|
-
/** monitor 项目
|
|
3
|
-
|
|
2
|
+
/** monitor 项目 client key(前缀 `fm_ck_`),浏览器 / SSR 上报使用,会出现在客户端 bundle 中。 */
|
|
3
|
+
clientKey: string;
|
|
4
|
+
/** monitor 项目 auth token(前缀 `fm_at_`),仅供构建机上传 sourcemap 使用。 */
|
|
5
|
+
authToken: string;
|
|
4
6
|
/** monitor 服务的 base URL,例如 `https://monitor.example.com`。`/api/report`、`/api/upload` 由下游 tracking / plugin-webpack 内部拼接。 */
|
|
5
7
|
url: string;
|
|
6
8
|
/** Commit hash,由调用方自行解析(如 `git rev-parse HEAD`)。 */
|
|
7
9
|
commit: string;
|
|
10
|
+
/**
|
|
11
|
+
* 用户 app 的对外访问 URL(如 `https://app.example.com`),仅用于 SSR 错误上报里把 `req.url`(path)补成完整地址。
|
|
12
|
+
* 不配则按以下顺序探测:`X-Forwarded-Proto + X-Forwarded-Host` → `req.connection.encrypted + req.headers.host`。
|
|
13
|
+
* Docker / k8s 部署若反代未透传 `X-Forwarded-*` header,强烈建议显式配置此项。
|
|
14
|
+
*/
|
|
15
|
+
publicUrl?: string;
|
|
8
16
|
}
|
|
9
17
|
interface NuxtBuildContext {
|
|
10
18
|
isClient: boolean;
|
|
@@ -53,7 +61,8 @@ interface NuxtModuleThis {
|
|
|
53
61
|
* modules: [
|
|
54
62
|
* ['@tourmind-frontend/monitor-plugin-nuxt', {
|
|
55
63
|
* url: 'https://monitor.example.com',
|
|
56
|
-
*
|
|
64
|
+
* clientKey: process.env.MONITOR_CLIENT_KEY,
|
|
65
|
+
* authToken: process.env.MONITOR_AUTH_TOKEN,
|
|
57
66
|
* commit: process.env.GIT_COMMIT,
|
|
58
67
|
* }],
|
|
59
68
|
* ],
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@tourmind-frontend/monitor-plugin-nuxt",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.4.1",
|
|
4
4
|
"description": "Nuxt 2 module that captures runtime errors and uploads sourcemaps to a frontend-monitor server.",
|
|
5
5
|
"main": "./dist/index.cjs",
|
|
6
6
|
"types": "./dist/index.d.ts",
|
|
@@ -17,12 +17,12 @@
|
|
|
17
17
|
"node": ">=13"
|
|
18
18
|
},
|
|
19
19
|
"dependencies": {
|
|
20
|
-
"@tourmind-frontend/monitor-plugin-webpack": "^1.
|
|
20
|
+
"@tourmind-frontend/monitor-plugin-webpack": "^1.4.0"
|
|
21
21
|
},
|
|
22
22
|
"peerDependencies": {
|
|
23
23
|
"nuxt": "^2.4.0",
|
|
24
24
|
"vue": "^2.5.0",
|
|
25
|
-
"@tourmind-frontend/monitor-tracking": "^1.
|
|
25
|
+
"@tourmind-frontend/monitor-tracking": "^1.4.0"
|
|
26
26
|
},
|
|
27
27
|
"devDependencies": {
|
|
28
28
|
"@types/node": "^20.0.0",
|
|
@@ -5,7 +5,7 @@ import { register } from "@tourmind-frontend/monitor-tracking";
|
|
|
5
5
|
export default function () {
|
|
6
6
|
register({
|
|
7
7
|
url: "<%= options.url %>",
|
|
8
|
-
|
|
8
|
+
clientKey: "<%= options.clientKey %>",
|
|
9
9
|
// 桥接 Vue 2 的 errorHandler,链式调用既有 handler,不覆盖。
|
|
10
10
|
listener: function (handler) {
|
|
11
11
|
var existing = Vue.config.errorHandler;
|