mindmount/dist/mount.controller.js
2026-09-11 23:30:20 -04:00

112 lines
No EOL
4.9 KiB
JavaScript

"use strict";
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
return c > 3 && r && Object.defineProperty(target, key, r), r;
};
var __metadata = (this && this.__metadata) || function (k, v) {
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
};
var __param = (this && this.__param) || function (paramIndex, decorator) {
return function (target, key) { decorator(target, key, paramIndex); }
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.MountController = void 0;
const common_1 = require("@nestjs/common");
const swagger_1 = require("@nestjs/swagger");
const mount_service_1 = require("./mount.service");
let MountController = class MountController {
mount;
constructor(mount) {
this.mount = mount;
}
health() {
return {
ok: true,
service: 'mindmount',
routes: {
'/ips/{*path}': this.mount.gapmindBase() + '/*',
'/socials/{*path}': this.mount.socmindBase() + '/*',
},
gapmindTokenProvisioned: Boolean(this.mount.serviceToken()),
};
}
routes() {
return [
{ prefix: '/ips/{*path}', target: this.mount.gapmindBase(), auth: 'mount token, gapmind service token injected' },
{ prefix: '/socials/{*path}', target: this.mount.socmindBase(), auth: 'mount token' },
];
}
async ips(req, res, auth) {
return this.forward(req, res, auth, this.mount.gapmindBase(), '/ips', true);
}
async socials(req, res, auth) {
return this.forward(req, res, auth, this.mount.socmindBase(), '/socials', false);
}
async forward(req, res, auth, base, prefix, injectToken) {
try {
this.mount.requireMountAuth(auth);
}
catch (e) {
return res.status(e.status || 401).send({ message: e.message || 'Unauthorized' });
}
const rawUrl = req.raw?.url || req.url || '/';
const [path, query] = rawUrl.split('?');
const subpath = path.slice(prefix.length) || '/';
try {
const out = await this.mount.proxy(base, subpath, req.method, query || '', (req.headers || {}), req.body, injectToken);
if (out.contentType)
res.header('Content-Type', out.contentType);
return res.status(out.status).send(out.buffer);
}
catch (e) {
return res
.status(502)
.send({ message: 'Upstream unreachable', detail: e instanceof Error ? e.message : String(e) });
}
}
};
exports.MountController = MountController;
__decorate([
(0, common_1.Get)('health'),
(0, swagger_1.ApiOperation)({ summary: 'Health + upstream targets' }),
(0, swagger_1.ApiResponse)({ status: 200, description: 'Mount status' }),
__metadata("design:type", Function),
__metadata("design:paramtypes", []),
__metadata("design:returntype", void 0)
], MountController.prototype, "health", null);
__decorate([
(0, common_1.Get)('api/routes'),
(0, swagger_1.ApiOperation)({ summary: 'List proxied routes' }),
(0, swagger_1.ApiResponse)({ status: 200, description: 'Route table' }),
__metadata("design:type", Function),
__metadata("design:paramtypes", []),
__metadata("design:returntype", void 0)
], MountController.prototype, "routes", null);
__decorate([
(0, common_1.All)('ips/{*path}'),
(0, swagger_1.ApiOperation)({ summary: 'Proxy to gapmind (IP intelligence)' }),
__param(0, (0, common_1.Req)()),
__param(1, (0, common_1.Res)()),
__param(2, (0, common_1.Headers)('authorization')),
__metadata("design:type", Function),
__metadata("design:paramtypes", [Object, Object, String]),
__metadata("design:returntype", Promise)
], MountController.prototype, "ips", null);
__decorate([
(0, common_1.All)('socials/{*path}'),
(0, swagger_1.ApiOperation)({ summary: 'Proxy to socmind (social intelligence)' }),
__param(0, (0, common_1.Req)()),
__param(1, (0, common_1.Res)()),
__param(2, (0, common_1.Headers)('authorization')),
__metadata("design:type", Function),
__metadata("design:paramtypes", [Object, Object, String]),
__metadata("design:returntype", Promise)
], MountController.prototype, "socials", null);
exports.MountController = MountController = __decorate([
(0, swagger_1.ApiTags)('Mount'),
(0, common_1.Controller)(),
__metadata("design:paramtypes", [mount_service_1.MountService])
], MountController);
//# sourceMappingURL=mount.controller.js.map