diff --git a/v2/server.js b/v2/server.js index 2758419..c590ac3 100644 --- a/v2/server.js +++ b/v2/server.js @@ -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('Impersonation Check' - + '' - + '

✅ Impersonation Check — работает!

' - + '

Путь /v2/impersonation-check доступен.

' - + '

Версия: ' + config.version + '

' - + '

← На CRUD

' - + ''); - }); + // ── 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('

Нет токена

Войти

'); - // ── /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());