trm-core
Version:
TRM (Transport Request Manager) Core
46 lines (45 loc) • 2.14 kB
JavaScript
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
return new (P || (P = Promise))(function (resolve, reject) {
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
step((generator = generator.apply(thisArg, _arguments || [])).next());
});
};
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.Protocol = void 0;
const protocol_registry_1 = __importDefault(require("protocol-registry"));
const express_1 = __importDefault(require("express"));
const path_1 = __importDefault(require("path"));
class Protocol {
constructor() { }
run() {
if (!this._app) {
this._app = (0, express_1.default)();
this._app.use(express_1.default.json());
this._server = this._app.listen(0, () => __awaiter(this, void 0, void 0, function* () {
const nodePath = process.execPath;
const address = this._server.address();
const url = `http://localhost:${address.port}`;
yield protocol_registry_1.default.register(`trm`, `"${nodePath}" "${path_1.default.join(__dirname, "./callback.js")}" ${url} $_URL_`, {
override: true,
terminal: true
});
}));
}
return new Promise((resolve, reject) => {
this._app.post('/', (req, res, next) => {
res.sendStatus(200);
this._server.close();
const data = req.body;
resolve(data);
});
});
}
}
exports.Protocol = Protocol;
;