Skip to content

Commit

Permalink
updated to angular 18
Browse files Browse the repository at this point in the history
  • Loading branch information
tim-fabian committed Jun 1, 2024
1 parent ef13634 commit 00a75b6
Show file tree
Hide file tree
Showing 48 changed files with 8,906 additions and 8,119 deletions.
25 changes: 0 additions & 25 deletions .eslintrc.json

This file was deleted.

4 changes: 2 additions & 2 deletions api/add-push-subscriber.route.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
/* eslint-disable jsdoc/require-jsdoc */
import { PUSH_SUBSCRIPTIONS } from './in-memory-db';
import { Request, Response } from 'express';
import { PushSubscription } from 'web-push';

import { PUSH_SUBSCRIPTIONS } from './in-memory-db';

export function addPushSubscription(req: Request, res: Response): void {
console.log('received req', req);
PUSH_SUBSCRIPTIONS.push(req.body as unknown as PushSubscription);
res.status(200).json({ message: 'Subscription added successfully.' });
}
10 changes: 4 additions & 6 deletions api/api.ts
Original file line number Diff line number Diff line change
@@ -1,18 +1,15 @@
/* eslint-disable @typescript-eslint/no-unsafe-argument */
/* eslint-disable no-console */
/* eslint-disable @typescript-eslint/no-unsafe-member-access */
/* eslint-disable @cspell/spellchecker */
import * as bodyParser from 'body-parser';
import * as cors from 'cors';
import * as express from 'express';
import { Application } from 'express';
import * as webpush from 'web-push';
import * as webPush from 'web-push';

import { addPushSubscription } from './add-push-subscriber.route';
import { PUSH_SUBSCRIPTIONS } from './in-memory-db';
import { SECRETS } from './secrets';
import { sendNotification } from './send-notification.route';

webpush.setVapidDetails(
webPush.setVapidDetails(
`mailto:${SECRETS.email}`,
SECRETS.publicKey,
SECRETS.privateKey
Expand All @@ -31,5 +28,6 @@ app.post('/send-notification', (req, res) => sendNotification(req, res));
app.get('/subscriptions', (req, res) => res.json(PUSH_SUBSCRIPTIONS));

app.listen(3000, () => {
// eslint-disable-next-line no-console
console.log('HTTP Server running at http://localhost:3000');
});
1 change: 1 addition & 0 deletions api/in-memory-db.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { PushSubscription } from 'web-push';

// eslint-disable-next-line jsdoc/require-jsdoc
export const PUSH_SUBSCRIPTIONS: PushSubscription[] = [];
27 changes: 16 additions & 11 deletions api/send-notification.route.ts
Original file line number Diff line number Diff line change
@@ -1,32 +1,37 @@
/* eslint-disable no-console */
/* eslint-disable jsdoc/require-jsdoc */
/* eslint-disable @cspell/spellchecker */
import { Request, Response } from 'express';
import * as webpush from 'web-push';
import * as webPush from 'web-push';

import { PUSH_SUBSCRIPTIONS } from './in-memory-db';

export function sendNotification(req: Request, res: Response): void {
// sample notification payload
// eslint-disable-next-line typescript/typedef
const notificationPayload = {
notification: {
title: 'Example Notification',
body: 'This notification is testing the ngx-pwa library.',
vibrate: [100, 50, 100],
data: {
'dateOfArrival': Date.now(),
'primaryKey': 1
dateOfArrival: Date.now(),
primaryKey: 1
},
actions: [{
action: 'explore',
title: 'Go to the site'
}]
actions: [
{
action: 'explore',
title: 'Go to the site'
}
]
}
};

Promise.all(PUSH_SUBSCRIPTIONS.map(sub => webpush.sendNotification(sub, JSON.stringify(notificationPayload))))
Promise.all(PUSH_SUBSCRIPTIONS.map(sub => webPush.sendNotification(sub, JSON.stringify(notificationPayload))))
// eslint-disable-next-line promise/prefer-await-to-then
.then(() => res.status(200).json({ message: 'Notification sent successfully.' }))
.catch(err => {
console.error('Error sending notification, reason: ', err);
// eslint-disable-next-line promise/prefer-await-to-then, promise/prefer-await-to-callbacks
.catch(error => {
console.error('Error sending notification, reason: ', error);
res.sendStatus(500);
});
}
3 changes: 3 additions & 0 deletions eslint.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
const config = require('eslint-config-service-soft');

module.exports = [...config];
Loading

0 comments on commit 00a75b6

Please sign in to comment.