'use strict'; const h3 = require('h3'); const plugin = require('nitropack/dist/runtime/plugin'); const index = plugin.defineNitroPlugin((nitroApp) => { void nitroApp.hooks.callHook("nitro:myPlugin"); nitroApp.router.use("/hello", h3.defineEventHandler((_event) => { return "world"; })); nitroApp.router.use("/_ws", h3.defineWebSocketHandler({ open(peer) { console.log("[ws] open", peer); }, message(peer, message) { console.log("[ws] message", peer, message); if (message.text().includes("ping")) { peer.send("pong"); } }, close(peer, event) { console.log("[ws] close", peer, event); }, error(peer, error) { console.log("[ws] error", peer, error); } })); const expressMiddleware = (req, res, next) => { console.log(`Request Method: ${req.method}, Request URL: ${req.url}`); res.end("Express middleware"); next(); }; nitroApp.router.use("/express", h3.fromNodeMiddleware(expressMiddleware)); }); module.exports = index;