Skip to content

Commit

Permalink
use plugin in registering http and websocket routes
Browse files Browse the repository at this point in the history
  • Loading branch information
nwaughachukwuma committed Feb 17, 2023
1 parent b56a033 commit a4734ff
Showing 1 changed file with 11 additions and 8 deletions.
19 changes: 11 additions & 8 deletions server/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,15 +20,18 @@ fastify()
console.log("not found", req.url);
reply.status(404).send({ error: "Not found" });
})
.get("/", async () => getEnvDetails())
.get("/ws/*", { websocket: true }, ({ socket }, req) => {
socket.on("message", (msg) => {
console.log("from client", msg.toString(), req.url);
const res = JSON.stringify({
pong: `acked: ${Date.now()}`,
msg: `${msg}`,
.register(async (app) => {
app.get("/", async () => getEnvDetails());

app.get("/ws/*", { websocket: true }, ({ socket }, req) => {
socket.on("message", (msg) => {
console.log("from client", msg.toString(), req.url);
const res = JSON.stringify({
pong: `acked: ${Date.now()}`,
msg: `${msg}`,
});
socket.send(res);
});
socket.send(res);
});
})
.listen({ port: PORT, host: ADDRESS })
Expand Down

0 comments on commit a4734ff

Please sign in to comment.