Created
October 25, 2015 19:54
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var capnp = require("capnp"); | |
var SandstormHttpBridge = | |
require("./sandstorm/sandstorm-http-bridge.capnp").SandstormHttpBridge; | |
var HackSessionContext = | |
require("./sandstorm/hack-session.capnp").HackSessionContext; | |
var http = require('http'); | |
http.createServer(function (req, res) { | |
var sessionId = req.headers["x-sandstorm-session-id"]; | |
console.log("sessionId: " + sessionId); | |
var conn = capnp.connect("unix:/tmp/sandstorm-api"); | |
var cap = conn.restore(null, SandstormHttpBridge); | |
cap.getSessionContext(sessionId).then(function (response) { | |
var hackSessionContext = response.context.castAs(HackSessionContext); | |
return hackSessionContext.httpGet("https://sandstorm.io"); | |
}).then(function (response) { | |
res.writeHead(200, {'Content-Type': response.mimeType}); | |
res.write(response.content); | |
res.end(); | |
}).catch(function (e) { | |
console.log("Error: " + e); | |
}); | |
}).listen(10000, '127.0.0.1'); | |
console.log('Server running at http://127.0.0.1:10000/'); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment