mirror of
https://github.com/webtorrent/bittorrent-tracker.git
synced 2024-12-15 11:56:25 +00:00
Merge pull request #48 from feross/public-onHttpRequest
onHttpRequest() as part of the public API
This commit is contained in:
commit
ed0dad4656
13
examples/express-embed/package.json
Normal file
13
examples/express-embed/package.json
Normal file
@ -0,0 +1,13 @@
|
|||||||
|
{
|
||||||
|
"name": "bittorrent-tracker-example-express-embed",
|
||||||
|
"version": "0.0.0",
|
||||||
|
"description": "Example for embedding bittorrent-tracker server in express.js",
|
||||||
|
"scripts": {
|
||||||
|
"server": "./server.js"
|
||||||
|
},
|
||||||
|
"author": "Astro <astro@spaceboyz.net>",
|
||||||
|
"license": "MIT",
|
||||||
|
"dependencies": {
|
||||||
|
"express": "^4.10.5"
|
||||||
|
}
|
||||||
|
}
|
16
examples/express-embed/server.js
Executable file
16
examples/express-embed/server.js
Executable file
@ -0,0 +1,16 @@
|
|||||||
|
#!/usr/bin/env node
|
||||||
|
|
||||||
|
var Server = require('../..').Server
|
||||||
|
var express = require('express')
|
||||||
|
var app = express()
|
||||||
|
|
||||||
|
var server = new Server({
|
||||||
|
http: false, // we do our own
|
||||||
|
udp: false // not interested
|
||||||
|
})
|
||||||
|
|
||||||
|
var onHttpRequest = server.onHttpRequest.bind(server)
|
||||||
|
app.get('/announce', onHttpRequest)
|
||||||
|
app.get('/scrape', onHttpRequest)
|
||||||
|
|
||||||
|
app.listen(8080)
|
@ -54,7 +54,7 @@ function Server (opts) {
|
|||||||
// default to starting an http server unless the user explictly says no
|
// default to starting an http server unless the user explictly says no
|
||||||
if (opts.http !== false) {
|
if (opts.http !== false) {
|
||||||
self._httpServer = http.createServer()
|
self._httpServer = http.createServer()
|
||||||
self._httpServer.on('request', self._onHttpRequest.bind(self))
|
self._httpServer.on('request', self.onHttpRequest.bind(self))
|
||||||
self._httpServer.on('error', self._onError.bind(self))
|
self._httpServer.on('error', self._onError.bind(self))
|
||||||
self._httpServer.on('listening', onListening)
|
self._httpServer.on('listening', onListening)
|
||||||
}
|
}
|
||||||
@ -123,7 +123,7 @@ Server.prototype.getSwarm = function (infoHash) {
|
|||||||
return swarm
|
return swarm
|
||||||
}
|
}
|
||||||
|
|
||||||
Server.prototype._onHttpRequest = function (req, res) {
|
Server.prototype.onHttpRequest = function (req, res) {
|
||||||
var self = this
|
var self = this
|
||||||
|
|
||||||
var params
|
var params
|
||||||
|
Loading…
Reference in New Issue
Block a user