Last active
October 26, 2024 15:09
-
-
Save nikolaybotev/3ce483bd1ceb3610f2ec85d4103c79f9 to your computer and use it in GitHub Desktop.
Deno serve over unix socket example with socket file cleanup
This file contains hidden or 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
const socketPath = "/tmp/mock-server"; | |
// Needed if starting with node --watch | |
try { | |
await Deno.remove(socketPath); | |
} catch (e) { | |
// ignore | |
} | |
let server = Deno.serve({ path: socketPath }, (_req) => new Response("Hello, world.")); | |
// Graceful shutdown (not invoked on deno --watch restarts) | |
Deno.addSignalListener("SIGINT", async () => { | |
console.log("Shutting down server..."); | |
await server.shutdown(); | |
await Deno.remove(socketPath); | |
console.log("Shut down server."); | |
Deno.exit(0); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment