This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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[] = []; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!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" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* 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) { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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'; | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 = {}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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'; | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { Router } from 'express'; | |
import PushController from '../controllers/NotificationController'; | |
class NotificationRoute { | |
private router: Router; | |
constructor() { | |
this.router = Router(); | |
this.setupRouter(); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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({ |