From cf47f8fe220d9388c204798b547699a44c27fab5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rafael=20C=C3=A1rdenas?= Date: Mon, 19 Feb 2024 11:44:05 -0600 Subject: [PATCH] fix: show status endpoint in /extended (#1869) --- docs/openapi.yaml | 2 +- src/api/init.ts | 7 +++++-- src/index.ts | 2 +- src/tests/other-tests.ts | 2 +- 4 files changed, 8 insertions(+), 5 deletions(-) diff --git a/docs/openapi.yaml b/docs/openapi.yaml index 345d98c844..677159c1e7 100644 --- a/docs/openapi.yaml +++ b/docs/openapi.yaml @@ -2003,7 +2003,7 @@ paths: example: $ref: ./api/core-node/get-info.example.json - /extended/v1/status: + /extended: get: summary: API status description: Retrieves the running status of the Stacks Blockchain API, including the server version and current chain tip information. diff --git a/src/api/init.ts b/src/api/init.ts index 6c7915a095..9295005748 100644 --- a/src/api/init.ts +++ b/src/api/init.ts @@ -150,7 +150,7 @@ export async function startApiServer(opts: { app.set('etag', false); app.get('/', (req, res) => { - res.redirect(`/extended/v1/status`); + res.redirect(`/extended/`); }); app.use('/doc', (req, res) => { @@ -189,6 +189,7 @@ export async function startApiServer(opts: { res.set('Cache-Control', 'no-store'); next(); }); + router.use('/', createStatusRouter(datastore)); router.use( '/v1', (() => { @@ -203,7 +204,9 @@ export async function startApiServer(opts: { v1.use('/info', createInfoRouter(datastore)); v1.use('/stx_supply', createStxSupplyRouter(datastore)); v1.use('/debug', createDebugRouter(datastore)); - v1.use('/status', createStatusRouter(datastore)); + v1.use('/status', (req, res) => + res.redirect(`${req.baseUrl.replace(/v1\/status/, '')}${getReqQuery(req)}`) + ); v1.use('/fee_rate', createFeeRateRouter(datastore)); v1.use('/tokens', createTokenRouter(datastore)); diff --git a/src/index.ts b/src/index.ts index 822951e4de..b4af319b38 100644 --- a/src/index.ts +++ b/src/index.ts @@ -110,7 +110,7 @@ async function init(): Promise { if (isProdEnv && !fs.existsSync('.git-info')) { throw new Error( 'File not found: .git-info. This generated file is required to display the running API version in the ' + - '`/extended/v1/status` endpoint. Please execute `npm run build` to regenerate it.' + '`/extended/` endpoint. Please execute `npm run build` to regenerate it.' ); } chainIdConfigurationCheck(); diff --git a/src/tests/other-tests.ts b/src/tests/other-tests.ts index 19489d4d47..f1276b170b 100644 --- a/src/tests/other-tests.ts +++ b/src/tests/other-tests.ts @@ -302,7 +302,7 @@ describe('other tests', () => { }); test('active status', async () => { - const result = await supertest(api.server).get(`/extended/v1/status/`); + const result = await supertest(api.server).get(`/extended/`); expect(result.body.status).toBe('ready'); });