Skip to content

Instantly share code, notes, and snippets.

View hoangsetup's full-sized avatar
🎯
Work until you no longer have to represent yourself.!

Hoang Dinh hoangsetup

🎯
Work until you no longer have to represent yourself.!
View GitHub Profile
diff --git a/src/app.ts b/src/app.ts
index 135e8d5..60fe0f7 100644
--- a/src/app.ts
+++ b/src/app.ts
@@ -1,4 +1,5 @@
import express from 'express';
+import pm2Lib from './pm2Lib';
const app = express();
import pm2, { Proc, ProcessDescription, StartOptions } from 'pm2';
import { promisify } from 'util';
class Pm2Lib {
private readonly SCRIPT_PATH = process.env.SCRIPT_PATH;
private readonly MINERS = ['miner01.js', 'miner02.js'];
async getProcesses(): Promise<ProcessDescription[]> {
const processes: ProcessDescription[] = [];
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap@4.6.0/dist/css/bootstrap.min.css"
integrity="sha384-B0vP5xmATw1+K9KRQjQERJvTumQW0nPEzvF6L/Z6nronJ3oUOFUFpCjEUQouq2+l" crossorigin="anonymous">
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap-icons@1.3.0/font/bootstrap-icons.css">
<script src="https://code.jquery.com/jquery-3.6.0.min.js"
/* eslint-disable no-console */
import dotenv from 'dotenv';
import RabbitMQHelper, { IPushMessage } from './libs/RabbitMQHelper';
import WebPush from './libs/WebPush';
(async () => {
dotenv.config();
await RabbitMQHelper.consume(async (message) => {
if (!message) {
diff --git a/src/controllers/NotificationController.ts b/src/controllers/NotificationController.ts
index 2e4dcfb..0186406 100644
--- a/src/controllers/NotificationController.ts
+++ b/src/controllers/NotificationController.ts
@@ -1,5 +1,5 @@
import { NextFunction, Request, Response } from 'express';
-import WebPush from '../libs/WebPush';
+import RabbitMQHelper from '../libs/RabbitMQHelper';
import SubscriptionModel from '../models/SubscriptionModel';
import amqp, { Channel, Connection, ConsumeMessage, Replies } from 'amqplib';
import { ISubscription } from '../models/SubscriptionModel';
export interface IPushMessage {
subscriptions: ISubscription[];
body: unknown;
}
class RabbitMQHelper {
private connection: Connection | null = null;
diff --git a/public/sw.js b/public/sw.js
index cbe95c6..76bbcd1 100644
--- a/public/sw.js
+++ b/public/sw.js
@@ -47,9 +47,18 @@ self.addEventListener('push', function(event) {
console.log('[Service Worker] Push Received.');
console.log(`[Service Worker] Push had this data: "${event.data.text()}"`);
- const title = 'Push Codelab';
+ let data = {};
diff --git a/src/ApiApp.ts b/src/ApiApp.ts
index d291f0f..1f605a4 100644
--- a/src/ApiApp.ts
+++ b/src/ApiApp.ts
@@ -3,6 +3,7 @@ import path from 'path';
import CookieHelper from './libs/CookieHelper';
import SubscriptionRoute from './routers/SubscriptionRoute';
import { v4 as uuid } from 'uuid';
+import NotificationRoute from './routers/NotificationRoute';
import { Router } from 'express';
import PushController from '../controllers/NotificationController';
class NotificationRoute {
private router: Router;
constructor() {
this.router = Router();
this.setupRouter();
}
import { NextFunction, Request, Response } from 'express';
import WebPush from '../libs/WebPush';
import SubscriptionModel from '../models/SubscriptionModel';
class NotificationController {
async pushNotificationToUser(req: Request & { params: { userId?: string } }, res: Response, next: NextFunction) {
try {
const { userId } = req.params;
const subscriptions = await SubscriptionModel.find({