Skip to content

Commit

Permalink
Merge pull request ziahamza#358 from pratikborsadiya/node-server
Browse files Browse the repository at this point in the history
Add support to use Node as webserver
  • Loading branch information
ziahamza committed Jun 28, 2017
2 parents dd4c322 + 4fe2e60 commit ce6aac5
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 1 deletion.
5 changes: 4 additions & 1 deletion README.md
Expand Up @@ -13,7 +13,10 @@ aria2c --enable-rpc --rpc-listen-all

If aria2 is not installed in your local machine then head on to https://aria2.github.io/ and follow the instructions there.

Then download the webui, you can either do that by downloading this repository and running index.html in the browser. Or you could just head on to https://ziahamza.github.io/webui-aria2/ and just start downloading files! After that you can also save it for offline use by saving from the browser save page as option.
Then download the webui, you can either do that by downloading this repository and running index.html in the browser. Or you could just head on to https://ziahamza.github.io/webui-aria2/ and just start downloading files! After that you can also save it for offline use by saving from the browser save page as option. You can also use node js to create simple server by using the following command from the download folder.
````bash
node node-server.js
````

Tips
====
Expand Down
36 changes: 36 additions & 0 deletions node-server.js
@@ -0,0 +1,36 @@
var http = require("http"),
url = require("url"),
path = require("path"),
fs = require("fs")
port = process.argv[2] || 8888;

http.createServer(function(request, response) {
var uri = url.parse(request.url).pathname,
filename = path.join(process.cwd(), uri);

fs.exists(filename, function(exists) {
if(!exists) {
response.writeHead(404, {"Content-Type": "text/plain"});
response.write("404 Not Found\n");
response.end();
return;
}

if (fs.statSync(filename).isDirectory()) filename += '/index.html';

fs.readFile(filename, "binary", function(err, file) {
if(err) {
response.writeHead(500, {"Content-Type": "text/plain"});
response.write(err + "\n");
response.end();
return;
}
response.writeHead(200);
response.write(file, "binary");
response.end();
});

});
}).listen(parseInt(port, 10));

console.log("WebUI Aria2 Server is running on http://localhost:" + port );

0 comments on commit ce6aac5

Please sign in to comment.