|
|
@ -44,32 +44,40 @@ class Server { |
|
|
|
|
|
|
|
|
|
|
|
private setupRoutes(): void { |
|
|
|
this.app.post('/subscribe', async (req: Request, res: Response) => { |
|
|
|
this.app.use(express.json()) |
|
|
|
this.app.post('/web-push/subscribe', async (req: Request, res: Response) => { |
|
|
|
const subscription = req.body as Subscription; |
|
|
|
console.log("/web-push/subscribe", req.body); |
|
|
|
await this.subscriptionService.addSubscription(subscription); |
|
|
|
res.status(201).send(); |
|
|
|
}); |
|
|
|
|
|
|
|
this.app.post('/unsubscribe', async (req: Request, res: Response) => { |
|
|
|
this.app.post('/web-push/unsubscribe', async (req: Request, res: Response) => { |
|
|
|
const subscription = req.body as Subscription; |
|
|
|
console.log(subscription); |
|
|
|
|
|
|
|
res.status(501).send(); |
|
|
|
}); |
|
|
|
|
|
|
|
this.app.post('/mute', async (req: Request, res: Response) => { |
|
|
|
this.app.post('/web-push/mute', async (req: Request, res: Response) => { |
|
|
|
const subscription = req.body as Subscription; |
|
|
|
console.log(subscription); |
|
|
|
|
|
|
|
res.status(501).send(); |
|
|
|
}); |
|
|
|
|
|
|
|
this.app.get('/vapid', async (_: Request, res: Response) => { |
|
|
|
this.app.get('/web-push/vapid', async (_: Request, res: Response) => { |
|
|
|
const vapidkeys: VapidKeys[] = await this.vapidService.getVapidKeys(); |
|
|
|
const vapidkey = vapidkeys[0]; |
|
|
|
|
|
|
|
res.send({"vapidKey": vapidkey['publicKey']}); |
|
|
|
}); |
|
|
|
|
|
|
|
this.app.use((req, _, next) => { |
|
|
|
console.log("Raw body:", req.body); |
|
|
|
next(); |
|
|
|
}); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
@ -95,6 +103,7 @@ class Server { |
|
|
|
}); |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
private setupWorkerListeners(): void { |
|
|
|
if (this.worker) { |
|
|
|
this.worker.on('message', (message) => { |
|
|
@ -107,6 +116,7 @@ class Server { |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
public start(): void { |
|
|
|
this.app.listen(this.port, () => { |
|
|
|
console.log(`Server is running on http://localhost:${this.port}`); |
|
|
@ -116,7 +126,6 @@ class Server { |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Initialize and start the server
|
|
|
|
|
|
|
|
const server = new Server(3000); |
|
|
|