@tourmind-frontend/monitor-plugin-nuxt 1.4.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 +19 -1
- package/dist/index.d.ts +6 -0
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -109,9 +109,11 @@ function MonitorModule(options) {
|
|
|
109
109
|
const ssrReportUrl = `${options.url.replace(/\/+$/, "")}/api/ssr-report`;
|
|
110
110
|
const clientKey = options.clientKey;
|
|
111
111
|
const commit = options.commit;
|
|
112
|
+
const publicUrlBase = (options.publicUrl || "").replace(/\/+$/, "") || null;
|
|
112
113
|
const rootDir = this.options.rootDir || this.options.srcDir || process.cwd();
|
|
113
114
|
this.nuxt.hook("render:errorMiddleware", (app) => {
|
|
114
115
|
app.use((err, req, _res, next) => {
|
|
116
|
+
var _a;
|
|
115
117
|
if (typeof fetch === "function") {
|
|
116
118
|
try {
|
|
117
119
|
const e = err;
|
|
@@ -122,13 +124,29 @@ function MonitorModule(options) {
|
|
|
122
124
|
new RegExp(`(${frame.file.replace(/[.*+?^${}()|[\]\\]/g, "\\$&")}:)${frame.line}(:)`),
|
|
123
125
|
`$1${sourceCtx.line}$2`
|
|
124
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
|
+
}
|
|
125
143
|
fetch(ssrReportUrl, {
|
|
126
144
|
method: "POST",
|
|
127
145
|
headers: { "Content-Type": "application/json" },
|
|
128
146
|
body: JSON.stringify({
|
|
129
147
|
token: clientKey,
|
|
130
148
|
stack: refinedStack,
|
|
131
|
-
url:
|
|
149
|
+
url: fullUrl,
|
|
132
150
|
commit,
|
|
133
151
|
...sourceCtx || {}
|
|
134
152
|
})
|
package/dist/index.d.ts
CHANGED
|
@@ -7,6 +7,12 @@ export interface MonitorModuleOptions {
|
|
|
7
7
|
url: string;
|
|
8
8
|
/** Commit hash,由调用方自行解析(如 `git rev-parse HEAD`)。 */
|
|
9
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;
|
|
10
16
|
}
|
|
11
17
|
interface NuxtBuildContext {
|
|
12
18
|
isClient: boolean;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@tourmind-frontend/monitor-plugin-nuxt",
|
|
3
|
-
"version": "1.4.
|
|
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",
|