diff options
author | Daniel Narvaez <dwnarvaez@gmail.com> | 2013-01-29 13:29:18 (GMT) |
---|---|---|
committer | Daniel Narvaez <dwnarvaez@gmail.com> | 2013-01-29 13:29:18 (GMT) |
commit | b0300b8b2be63d788c83a54fb4ea7ad0a12ef1e9 (patch) | |
tree | 153e8cbe9f629fffefb67c6421f598770b7c1fa1 | |
parent | ecc2ab17ef0d8471eec0140ca89aa6541a3f5289 (diff) |
Implement basic file serving
-rwxr-xr-x | server/sugar-http-server | 44 |
1 files changed, 39 insertions, 5 deletions
diff --git a/server/sugar-http-server b/server/sugar-http-server index 3719802..788f55b 100755 --- a/server/sugar-http-server +++ b/server/sugar-http-server @@ -1,10 +1,44 @@ #!/usr/bin/env node var http = require("http"); +var dbus = require("node-dbus"); +var url = require("url"); +var static = require("node-static"); -http.createServer(function (req, res) { - res.writeHead(200, {"Content-Type": "text/plain"}); - res.end("Hello World\n"); -}).listen(8000, "localhost"); +var bundlePathMsg = Object.create(dbus.DBusMessage, { + destination: { + value: "org.laptop.Shell" + }, + path: { + value: "/org/laptop/Shell" + }, + iface: { + value: "org.laptop.Shell", + }, + member: { + value: 'GetBundlePath', + }, + bus: { + value: dbus.DBUS_BUS_SESSION + }, + type: { + value: dbus.DBUS_MESSAGE_TYPE_METHOD_RETURN + } +}); + +http.createServer(function(request, response) { + request.addListener('end', function () { + parsed = url.parse(request.url); + splittedPath = parsed.pathname.split("/") + + bundlePathMsg.on("methodResponse", function(path) { + var fileServer = new static.Server(path); -console.log("Server running at http://localhost:800/"); + filePath = splittedPath.slice(2).join("/") + fileServer.serveFile(filePath, 200, {}, request, response); + }); + + bundlePathMsg.appendArgs("s", splittedPath[1]); + bundlePathMsg.send(); + }); +}).listen(8000, "localhost"); |