Skip to content

Instantly share code, notes, and snippets.

@maroshii
Created July 25, 2017 21:11
Show Gist options
  • Save maroshii/b159d6e98c07d76d3c98414b152b0330 to your computer and use it in GitHub Desktop.
Save maroshii/b159d6e98c07d76d3c98414b152b0330 to your computer and use it in GitHub Desktop.
Docker Proxy
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');
});
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