diff --git a/src/backend/controllers/hosting/HostingController.js b/src/backend/controllers/hosting/HostingController.js index d1ac44378..650aeb7e9 100644 --- a/src/backend/controllers/hosting/HostingController.js +++ b/src/backend/controllers/hosting/HostingController.js @@ -93,6 +93,22 @@ export class HostingController extends PuterController { userId: req.actor.user.id, }); + // Same event the `puter-subdomains` driver fires on delete — + // listeners (CDN purge, abuse tracking, worker cleanup) + // depend on it. + try { + this.clients.event.emit( + 'subdomain.delete', + { + subdomain: row.subdomain, + uid: String(row.uuid), + }, + {}, + ); + } catch { + // Non-critical. + } + res.json({}); }, ); diff --git a/src/backend/controllers/hosting/HostingController.test.js b/src/backend/controllers/hosting/HostingController.test.js index b9e9bc153..0eac28f74 100644 --- a/src/backend/controllers/hosting/HostingController.test.js +++ b/src/backend/controllers/hosting/HostingController.test.js @@ -181,4 +181,24 @@ describe('HostingController /delete-site', () => { expect(captured.body).toEqual({}); expect(await server.stores.subdomain.getByUuid(site.uuid)).toBeNull(); }); + + it('emits subdomain.delete so listeners can purge caches', async () => { + const { userId, actor } = await makeUser(); + const site = await makeSite(userId); + const emitSpy = vi.spyOn(server.clients.event, 'emit'); + + try { + await deleteSite( + makeReq({ body: { site_uuid: site.uuid }, actor }), + makeRes().res, + ); + expect(emitSpy).toHaveBeenCalledWith( + 'subdomain.delete', + { subdomain: site.subdomain, uid: String(site.uuid) }, + {}, + ); + } finally { + emitSpy.mockRestore(); + } + }); });