mirror of
https://github.com/kemko/nomad.git
synced 2026-01-14 14:25:42 +03:00
This connects Xterm.js to a Nomad exec websocket so people can interact on clients via live sessions. There are buttons on job, allocation, task group, and task detail pages that open a popup that lets them edit their shell command and start a session. More is to come, as recorded in issues.
35 lines
974 B
JavaScript
35 lines
974 B
JavaScript
'use strict';
|
|
|
|
// Issue to improve: https://github.com/hashicorp/nomad/issues/7465
|
|
const proxyPath = '/v1';
|
|
|
|
module.exports = function(app, options) {
|
|
// For options, see:
|
|
// https://github.com/nodejitsu/node-http-proxy
|
|
|
|
let server = options.httpServer;
|
|
let proxy = require('http-proxy').createProxyServer({
|
|
target: 'http://localhost:4646',
|
|
ws: true,
|
|
changeOrigin: true
|
|
});
|
|
|
|
proxy.on('error', function(err, req) {
|
|
// eslint-disable-next-line
|
|
console.error(err, req.url);
|
|
});
|
|
|
|
app.use(proxyPath, function(req, res){
|
|
// include root path in proxied request
|
|
req.url = proxyPath + req.url;
|
|
proxy.web(req, res, { target: 'http://localhost:4646'});
|
|
});
|
|
|
|
server.on('upgrade', function (req, socket, head) {
|
|
if (req.url.startsWith('/v1/client/allocation') && req.url.includes('exec?')) {
|
|
req.headers.origin = 'http://localhost:4646';
|
|
proxy.ws(req, socket, head, { target: 'http://localhost:4646'});
|
|
}
|
|
});
|
|
};
|