bittorrent-tracker/examples/express-embed/server.js
Cas e6d3189edf
feat: esm (#431)
BREAKING CHANGE: ESM only

* feat: esm

* fix: linter oops
2022-12-05 23:06:54 +01:00

29 lines
737 B
JavaScript
Executable File

#!/usr/bin/env node
import { Server } from '../../index.js'
import express from 'express'
const app = express()
// https://wiki.theory.org/BitTorrentSpecification#peer_id
const whitelist = {
UT: true // uTorrent
}
const server = new Server({
http: false, // we do our own
udp: false, // not interested
ws: false, // not interested
filter (params) {
// black/whitelist for disallowing/allowing specific clients [default=allow all]
// this example only allows the uTorrent client
const client = params.peer_id[1] + params.peer_id[2]
return whitelist[client]
}
})
const onHttpRequest = server.onHttpRequest.bind(server)
app.get('/announce', onHttpRequest)
app.get('/scrape', onHttpRequest)
app.listen(8080)