Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Need cleaner way to programmatically start an http server for a torrent #158

Closed
feross opened this issue Oct 22, 2014 · 5 comments
Closed

Need cleaner way to programmatically start an http server for a torrent #158

feross opened this issue Oct 22, 2014 · 5 comments
Labels

Comments

@feross
Copy link
Member

@feross feross commented Oct 22, 2014

Opening an issue to track this feature request from @sammuel86.

@feross feross added the enhancement label Oct 22, 2014
@feross

This comment has been minimized.

Copy link
Member Author

@feross feross commented Oct 22, 2014

This is complete now. From the readme:

torrent.createServer([opts])

Create an http server to serve the contents of this torrent, dynamically fetching the
needed torrent pieces to satisfy http requests. Range requests are supported.

Returns an http.Server instance (got from calling http.createServer). If opts is specified, it is passed to the http.createServer function.

Visiting the root of the server / will show a list of links to individual files. Access
individual files at /<index> where <index> is the index in the torrent.files array
(e.g. /0, /1, etc.)

Here is a usage example:

var client = new WebTorrent()
client.add(magnet_uri, function (torrent) {
  // create HTTP server for this torrent
  var server = torrent.createServer()
  server.listen(port) // start the server listening to a port

  // visit http://localhost:<port>/ to see a list of files

  // access individual files at http://localhost:<port>/<index> where index is the index
  // in the torrent.files array

  // later, cleanup...
  server.close()
  client.destroy()
})
@feross feross closed this Oct 22, 2014
@paulxiong

This comment has been minimized.

Copy link

@paulxiong paulxiong commented Feb 2, 2016

torrent.createServer() works in browser?

@DiegoRBaquero

This comment has been minimized.

Copy link
Member

@DiegoRBaquero DiegoRBaquero commented Feb 2, 2016

Nope.

On Feb 1, 2016, at 7:02 PM, Paul Xiong notifications@github.com wrote:

torrent.createServer() works in browser?


Reply to this email directly or view it on GitHub.

@feross

This comment has been minimized.

Copy link
Member Author

@feross feross commented Feb 7, 2016

@paulxiong Use torrent.appendTo() if you want to add the torrent to your webpage.

@lock

This comment has been minimized.

Copy link

@lock lock bot commented May 4, 2018

This thread has been automatically locked because it has not had recent activity. To discuss futher, please open a new issue.

@lock lock bot locked as resolved and limited conversation to collaborators May 4, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
3 participants
You can’t perform that action at this time.