Skip to content

Instantly share code, notes, and snippets.

@eed3si9n
Created December 8, 2017 04:24
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save eed3si9n/0ee26a15218f1d4031b451dd61315d6c to your computer and use it in GitHub Desktop.
Save eed3si9n/0ee26a15218f1d4031b451dd61315d6c to your computer and use it in GitHub Desktop.
'use strict';
Object.defineProperty(exports, "__esModule", { value: true });
const path = require("path");
const url = require("url");
let net = require('net'), fs = require('fs'), os = require('os'), stdin = process.stdin, stdout = process.stdout;
let u = discoverUrl();
let socket = net.Socket();
socket.on('data', (chunk) => {
// send it back to stdout
stdout.write(chunk);
}).on('end', () => {
stdin.pause();
});
if (u.protocol == 'tcp:') {
socket.connect(u.port, '127.0.0.1');
}
else if (u.protocol == 'local:' && os.platform() == 'win32') {
let pipePath = '\\\\.\\pipe\\' + u.hostname;
socket.connect(pipePath);
}
else if (u.protocol == 'local:') {
socket.connect(u.path);
}
else {
throw 'Unknown protocol ' + u.protocol;
}
stdin.resume();
stdin.on('data', (chunk) => {
socket.write(chunk);
}).on('end', () => {
socket.end();
});
// the port file is hardcoded to a particular location relative to the build.
function discoverUrl() {
let pf = path.join(process.cwd(), 'project', 'target', 'active.json');
let portfile = JSON.parse(fs.readFileSync(pf));
return url.parse(portfile.uri);
}
//# sourceMappingURL=server.js.map
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment