要解决Bugsnag显示缩小文件的URL而不是上传的sourcemap文件的问题,您可以使用Bugsnag提供的API来上传sourcemap文件。
以下是一个示例,演示如何使用Node.js上传sourcemap文件到Bugsnag:
const axios = require('axios');
const fs = require('fs');
// 读取sourcemap文件
const sourcemapFile = fs.readFileSync('path/to/sourcemap.js.map');
// 构建上传URL
const uploadUrl = 'https://upload.bugsnag.com';
// 构建请求头
const headers = {
'Content-Type': 'application/json',
'Bugsnag-Api-Key': 'YOUR_API_KEY', // 替换为您自己的API密钥
};
// 构建请求体
const formData = {
apiKey: 'YOUR_API_KEY', // 替换为您自己的API密钥
appVersion: '1.0.0', // 您的应用程序版本
minifiedUrl: 'https://yourwebsite.com/path/to/minified.js', // 缩小文件的URL
sourceMap: sourcemapFile.toString('base64'), // 将sourcemap文件转换为base64编码
};
// 发送POST请求上传sourcemap文件
axios.post(uploadUrl, formData, { headers })
.then(response => {
console.log('Sourcemap文件上传成功');
})
.catch(error => {
console.error('Sourcemap文件上传失败', error);
});
请注意,您需要将YOUR_API_KEY
替换为您自己的Bugsnag API密钥,并且确保sourcemap.js.map
文件位于您指定的路径中。
使用此代码示例,您可以将sourcemap文件上传到Bugsnag,并确保Bugsnag正确显示缩小文件的源代码,而不仅仅是URL。