问题:
由于JavaScript代码加载的问题,我尝试将sentry与tunnel选项集成在一起。如果用户启用了广告拦截器,这将防止拦截。https://docs.sentry.io/platforms/javascript/troubleshooting/#using-the-tunnel-option
现在,他们在文档中提供了此隧道的示例代码:
<?php
// Change $host appropriately if you run your own Sentry instance.
$host = "sentry.io";
// Set $known_project_ids to an array with your Sentry project IDs which you
// want to accept through this proxy.
$known_project_ids = array( );
$envelope = stream_get_contents(STDIN);
$pieces = explode("\n", $envelope, 2);
$header = json_decode($pieces[0], true);
if (isset($header["dsn"])) {
$dsn = parse_url($header["dsn"]);
$project_id = intval(trim($dsn["path"], "/"));
if (in_array($project_id, $known_project_ids)) {
$options = array(
'http' => array(
'header' => "Content-type: application/x-sentry-envelope\r\n",
'method' => 'POST',
'content' => $envelope
)
);
echo file_get_contents(
"https://$host/api/$project_id/envelope/",
false,
stream_context_create($options));
}
}
在app.php
(我的项目的布局文件)中,我这样调用JavaScript Sentry:
<script src="{{ asset('/assets/js/app.js') }}" crossorigin="anonymous"></script>
我的问题:
我不明白的是如何将它作为一个路由集成到web.php中,所以每次发生JavaScript错误时都会调用它。
1条答案
按热度按时间ekqde3dh1#
您应该能够像这样定义路由:
然后从JavaScript调用URL '/sentry-tunnel'。如果需要,不要忘记添加您的项目ID和凭据。