mirror of
https://github.com/Paris-est-Ludique/intranet.git
synced 2025-06-10 01:24:20 +02:00
28 lines
802 B
TypeScript
28 lines
802 B
TypeScript
import { Request, Response, NextFunction } from "express"
|
|
import webpush from "web-push"
|
|
|
|
const publicKey = process.env.FORCE_ORANGE_PUBLIC_VAPID_KEY
|
|
const privateKey = process.env.FORCE_ORANGE_PRIVATE_VAPID_KEY
|
|
if (publicKey && privateKey) {
|
|
webpush.setVapidDetails("mailto: contact@parisestludique.fr", publicKey, privateKey)
|
|
}
|
|
|
|
export default function notificationsSubscribe(
|
|
request: Request,
|
|
response: Response,
|
|
_next: NextFunction
|
|
): void {
|
|
const subscription = request.body
|
|
|
|
const payload = JSON.stringify({
|
|
title: "Hello!",
|
|
body: "It works.",
|
|
})
|
|
webpush
|
|
.sendNotification(subscription, payload)
|
|
.then((result) => console.log(result))
|
|
.catch((e) => console.log(e.stack))
|
|
|
|
response.status(200).json({ success: true })
|
|
}
|