import { createLibp2p } from 'libp2p'
import { canHandle } from '@libp2p/http/servers'
import createServer from 'node:http'
const libp2p = await createLibp2p({
// ...options
})
const handled = canHandle(libp2p)
createServer((req, res) => {
if (handled(req, res)) {
// libp2p handled the request, nothing else to do
return
}
// handle request normally - pass off to express/fastify/etc or return 404
})
Helper function to determine whether the passed libp2p node handled the incoming HTTP or WebSocket request.