te')); return $arr; } /* 遍历用户所有主题 * @param $uid 用户ID * @param int $page 页数 * @param int $pagesize 每页记录条数 * @param bool $desc 排序方式 TRUE降序 FALSE升序 * @param string $key 返回的数组用那一列的值作为 key * @param array $col 查询哪些列 */ function thread_tid_find_by_uid($uid, $page = 1, $pagesize = 1000, $desc = TRUE, $key = 'tid', $col = array()) { if (empty($uid)) return array(); $orderby = TRUE == $desc ? -1 : 1; $arr = thread_tid__find($cond = array('uid' => $uid), array('tid' => $orderby), $page, $pagesize, $key, $col); return $arr; } // 遍历栏目下tid 支持数组 $fid = array(1,2,3) function thread_tid_find_by_fid($fid, $page = 1, $pagesize = 1000, $desc = TRUE) { if (empty($fid)) return array(); $orderby = TRUE == $desc ? -1 : 1; $arr = thread_tid__find($cond = array('fid' => $fid), array('tid' => $orderby), $page, $pagesize, 'tid', array('tid', 'verify_date')); return $arr; } function thread_tid_delete($tid) { if (empty($tid)) return FALSE; $r = thread_tid__delete(array('tid' => $tid)); return $r; } function thread_tid_count() { $n = thread_tid__count(); return $n; } // 统计用户主题数 大数量下严谨使用非主键统计 function thread_uid_count($uid) { $n = thread_tid__count(array('uid' => $uid)); return $n; } // 统计栏目主题数 大数量下严谨使用非主键统计 function thread_fid_count($fid) { $n = thread_tid__count(array('fid' => $fid)); return $n; } ?>javascript - The script resource is behind a redirect, which is disallowed - Stack Overflow
最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - The script resource is behind a redirect, which is disallowed - Stack Overflow

programmeradmin4浏览0评论

I'm implementing firebase messaging but i'm getting a error on console in chrome.

The script resource is behind a redirect, which is disallowed. /firebase-messaging-sw.js Failed to load resource: net::ERR_UNSAFE_REDIRECT

The file /firebase-messaging-sw.js is in public folder and i'm using FCM installation like this 

But the link the authorization is a link like . but the main web site is on main.domain

I'm implementing firebase messaging but i'm getting a error on console in chrome.

The script resource is behind a redirect, which is disallowed. /firebase-messaging-sw.js Failed to load resource: net::ERR_UNSAFE_REDIRECT

The file /firebase-messaging-sw.js is in public folder and i'm using FCM installation like this https://github./firebase/quickstart-js/tree/master/messaging

But the link the authorization is a link like https://09029e3f.ngrok.io/admin/pt/settings/notifications. but the main web site is on main.domain.

Share Improve this question edited Apr 10, 2017 at 14:17 Frank van Puffelen 600k85 gold badges889 silver badges859 bronze badges asked Apr 10, 2017 at 11:02 Carlos VieiraCarlos Vieira 6073 gold badges12 silver badges22 bronze badges
Add a ment  | 

3 Answers 3

Reset to default 3

Firebase answer and its working

The service worker script (firebase-messaging-sw.js) is expected to be on the absolute path of the application by default. Using the quickstart project, the location will be http://localhost:5000/firebase-messaging-sw.js.

Since you're using a different server for the static files storage, the service worker script location might not be the same or in place. With this, we need to update the service worker registration code implementation and call the service worker script from a different location.

Find the static location of the service worker script. In my case, it is http://localhost:5000/sw/firebase-messaging.sw.js, since I moved the service worker script location inside the sw folder. To verify that it is accessible, try to input the url in the browser address bar and the service worker script code should be displayed. Download the firebase.js script locally from https://www.gstatic./firebasejs//firebase.js and call it /firebase.js"> on the web pages that need to show a notification.

Update the firebase-messaging.js script. Find the keywords firebase-messaging-sw.js and , then add the path as prefix. In my case, it is http://localhost:5000/sw/firebase-messaging-sw.js and http://localhost:5000/sw/firebase-cloud-messaging-push-scope.

Many thanks firebase

You can fix that by loading firebase-messaging-sw.js manually using service worker.
Suppose you have 2 files: index.html and firebase-message-sw.js. They are on the same location.

1.In the index.html, you load firebase.js and initialize your firebase app:

<script src="https://www.gstatic./firebasejs/4.3.1/firebase.js"></script>
<script>
  var var config = {
        apiKey: YOUR_API_KEY,
        messagingSenderId: YOUR_SENDER_ID
    };
    firebase.initializeApp(config);
    navigator.serviceWorker.register('/firebase-messaging-sw.js')
      .then(function (registration) {
          messaging = firebase.messaging();

         //request permission for Push Message.
          messaging.requestPermission().then(function () {
              console.log('grant');

              messaging.getToken().then(function (currentToken) {
                 console.log('current token', currentToken);
            });
          }).catch(function(error) {
               console.log('Push Message is disallowed');
          })
      })
</script>

2. Implement firebase-messaing-sw.js

importScripts('https://www.gstatic./firebasejs/4.3.1/firebase-app.js');
importScripts('https://www.gstatic./firebasejs/4.3.1/firebase-messaging.js');
var config = {
    messagingSenderId: YOUR_SENDER_ID
};
firebase.initializeApp(config);
const messaging = firebase.messaging();

messaging.setBackgroundMessageHandler(function (payload) {
    console.log('[firebase-messaging-sw.js] Received background message ', payload);
    // Customize notification here
    const notificationTitle = 'Background Message Title';
    const notificationOptions = {
        body: 'Background Message body.',
        icon: '/firebase-logo.png'
    };

    return self.registration.showNotification(notificationTitle,
        notificationOptions);
});

Done!

I'm using next 13 and I handle it with middlewear like this:

if (pathname === '/firebase-messaging-sw.js') return NextResponse.next();

发布评论

评论列表(0)

  1. 暂无评论