DOMPurify can work on server with a dom library.
They suggest jsdom
in their docs.
You should also check out isomorphic-dompurify for a convenient solution for running it both in client and server.
Since I'm currently running into problems with isomorphic-dompurify inside Astro I can't promise you success :)