@crack_user

Почему не отправляется push-уведомление?

const webpush = require('web-push');

// VAPID keys should be generated only once.
const vapidKeys = {
    publicKey:
        "123",
    privateKey: "123",
};

webpush.setVapidDetails(
    'mailto:example@yourdomain.org',
    vapidKeys.publicKey,
    vapidKeys.privateKey
);
// Payload уведомления
const payload = JSON.stringify({
    title: "Новое уведомление!",
    body: "лол"
});
// This is the same output of calling JSON.stringify on a PushSubscription
const pushSubscription = {
    endpoint: process.argv[2],
    keys: {
        p256dh: process.argv[3],
        auth: process.argv[4]
    }
};

webpush.sendNotification(pushSubscription, payload)
    .then((result) => {
        console.log("Notification sent successfully.", result);
    })
    .catch(error => {
        console.error("Error sending notification:", error);
    });


Получаю ответ о том, что уведомление было отправлено(Notification sent successfully.), но мне ничего не пришло
endpoint, p256dh, auth - всё корректное

result -
statusCode: 201,
  body: '',
  headers: {
    location: 'https://fcm.googleapis.com/0:1714822492441112%e609af1cf9fd7ecd',
    'x-content-type-options': 'nosniff',
    'x-frame-options': 'SAMEORIGIN',
    'x-xss-protection': '0',
    date: 'Sat, 04 May 2024 11:34:52 GMT',
    'content-length': '0',
    'content-type': 'text/html; charset=UTF-8',
    'alt-svc': 'h3=":443"; ma=2592000,h3-29=":443"; ma=2592000'
  }
  • Вопрос задан
  • 68 просмотров
Пригласить эксперта
Ответы на вопрос 1
@crack_user Автор вопроса
Отправил уведомления с локалки, а не с хоста, всё прошло, теперь осталось думать, почему так и что нужно настроить
Ответ написан
Комментировать
Ваш ответ на вопрос

Войдите, чтобы написать ответ

Войти через центр авторизации
Похожие вопросы