Created
July 25, 2017 21:11
-
-
Save maroshii/b159d6e98c07d76d3c98414b152b0330 to your computer and use it in GitHub Desktop.
Docker Proxy
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
const path = require('path'); | |
const express = require('express'); | |
const proxy = require('http-proxy-middleware'); | |
const app = express(); | |
app.use('/version', proxy({ | |
target: { | |
socketPath: '/var/run/docker.sock', | |
} | |
})); | |
app.use('/static', express.static(path.resolve(__dirname, 'static'))) | |
app.get('*', (req, res) => { | |
res.send(` | |
<!DOCTYPE html> | |
<html> | |
<head> | |
<meta charset="utf-8"> | |
<title>Docker proxy</title> | |
</head> | |
<body></body> | |
<script src="/static/main.js"></script> | |
</html> | |
`); | |
}) | |
app.listen(3000, () => { | |
console.log('listening on port 3000'); | |
}); |
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
fetch('/version').then(function(r) { | |
return r.json() | |
}).then(function(j) { | |
document.write(JSON.stringify(j)); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment