2016-10-11 08:58:23 +00:00
|
|
|
var exec = require("child_process").exec,
|
|
|
|
express = require('express'),
|
2017-01-11 19:10:39 +00:00
|
|
|
httpProxy = require("http-proxy"),
|
2016-10-11 08:58:23 +00:00
|
|
|
router = express.Router(),
|
|
|
|
gitBackend = require("git-http-backend"),
|
|
|
|
spawn = require("child_process").spawn
|
|
|
|
|
2017-03-18 13:30:21 +00:00
|
|
|
router.get('/', (req, res) => {
|
2016-10-11 08:58:23 +00:00
|
|
|
const sessionId = req.headers["x-sandstorm-session-id"]
|
|
|
|
exec(`getPublicId ${sessionId}`, (err, rv) => {
|
|
|
|
if(err)
|
|
|
|
return res.end(err)
|
|
|
|
const lines = rv.split("\n")
|
|
|
|
const publicId = lines[0]
|
|
|
|
const hostname = lines[1]
|
|
|
|
const domain = publicId+"."+hostname
|
|
|
|
const url = lines[2]
|
|
|
|
const isDemo = lines[3] == "true"
|
2017-03-18 13:30:21 +00:00
|
|
|
res.render("index", {domain, isDemo, publicId, url})
|
2016-10-11 08:58:23 +00:00
|
|
|
})
|
|
|
|
})
|
|
|
|
|
|
|
|
router.use("/git", (req, res) => {
|
|
|
|
req.pipe(gitBackend(req.url, (err, service) => {
|
|
|
|
if(err)
|
|
|
|
return res.end(err+"\n")
|
|
|
|
res.setHeader("content-type", service.type)
|
|
|
|
console.log("cmd", service.cmd)
|
|
|
|
const ps = spawn(service.cmd, service.args.concat("/var/git"))
|
|
|
|
ps.stdout.pipe(service.createStream()).pipe(ps.stdin)
|
|
|
|
})).pipe(res)
|
|
|
|
})
|
|
|
|
|
2017-01-11 19:10:39 +00:00
|
|
|
var proxy = httpProxy.createProxyServer({
|
|
|
|
target: "http://127.0.0.1:8001/admin/",
|
|
|
|
changeOrigin: true
|
|
|
|
})
|
|
|
|
|
|
|
|
router.use("/admin/", (req, res) => proxy.web(req, res))
|
|
|
|
|
2016-10-11 08:58:23 +00:00
|
|
|
module.exports = router
|