v0.5.147: /v2/impersonation-check — 3 GET запроса к IAM с перехватом ошибок
This commit is contained in:
+23
-13
@@ -90,20 +90,30 @@ function createV2Router() {
|
||||
}
|
||||
});
|
||||
|
||||
// ── GET /v2/impersonation-check — тест: просто текст ─────────────
|
||||
router.get('/impersonation-check', (req, res) => {
|
||||
res.set('Content-Type', 'text/html; charset=utf-8');
|
||||
res.send('<!DOCTYPE html><html><head><meta charset="utf-8"><title>Impersonation Check</title>'
|
||||
+ '<style>body{font-family:monospace;background:#111;color:#eee;padding:40px;font-size:16px}'
|
||||
+ 'h2{color:#4fc3f7}.ok{color:#81c784}</style></head><body>'
|
||||
+ '<h2>✅ Impersonation Check — работает!</h2>'
|
||||
+ '<p>Путь <code>/v2/impersonation-check</code> доступен.</p>'
|
||||
+ '<p>Версия: ' + config.version + '</p>'
|
||||
+ '<p><a href="/v2/app" style="color:#80cbc4">← На CRUD</a></p>'
|
||||
+ '</body></html>');
|
||||
});
|
||||
// ── GET /v2/impersonation-check — IAM impersonation: 3 GET эндпоинта ──
|
||||
router.get('/impersonation-check', async (req, res) => {
|
||||
const token = req.session && req.session.token;
|
||||
if (!token) return res.send('<h2>Нет токена</h2><p><a href="/v2/login">Войти</a></p>');
|
||||
|
||||
// ── /v2/app — пользовательский CRUD (только с сессией) ──────────────
|
||||
const endpoints = [
|
||||
{ name: 'status', url: 'https://auth-api.ngcloud.ru/api/v1/impersonation/status' },
|
||||
{ name: 'history', url: 'https://auth-api.ngcloud.ru/api/v1/impersonation/history' },
|
||||
{ name: 'history/all', url: 'https://auth-api.ngcloud.ru/api/v1/impersonation/history/all' },
|
||||
];
|
||||
|
||||
const results = {};
|
||||
for (const ep of endpoints) {
|
||||
try {
|
||||
const data = await iamFetch(token, ep.url);
|
||||
results[ep.name] = { ok: true, data };
|
||||
} catch (e) {
|
||||
results[ep.name] = { ok: false, error: e.message };
|
||||
}
|
||||
}
|
||||
|
||||
res.set('Content-Type', 'text/html; charset=utf-8');
|
||||
res.send(iamStatPage(results));
|
||||
});
|
||||
|
||||
// ── /v2/app — пользовательский CRUD (только с сессией) ──────────────
|
||||
router.use('/app', enhanceImpersonation, resolveContext, createUserRouter());
|
||||
|
||||
Reference in New Issue
Block a user