Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

updated to angular 18 #12

Merged
merged 3 commits into from
Jun 1, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 0 additions & 25 deletions .eslintrc.json

This file was deleted.

2 changes: 1 addition & 1 deletion .github/workflows/deploy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ jobs:
if: github.event.pull_request.merged
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4
with:
# The branch, tag or SHA to checkout. When checking out the repository that
# triggered a workflow, this defaults to the reference or SHA for that event.
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ jobs:
runs-on: ubuntu-latest
steps:
# Checks-out your repository under $GITHUB_WORKSPACE, so your job can access it
- uses: actions/checkout@v3
- uses: actions/checkout@v4
# runs npm i inside the root directory
- name: npm i root
run: |
Expand All @@ -28,4 +28,4 @@ jobs:
- name: Linting
run: |
cd $GITHUB_WORKSPACE
npm run lint
npm run lint:ci
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