Merge pull request #358 from pratikborsadiya/node-server

Add support to use Node as webserver
This commit is contained in:
hamza zia 2017-06-28 08:19:52 +05:00 committed by GitHub
commit ce6aac5a3b
2 changed files with 40 additions and 1 deletions

View File

@ -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. 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 Tips
==== ====

36
node-server.js Normal file
View File

@ -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 );