From a2bd753649391288e8e80d1186c3fc6a40dc5e4a Mon Sep 17 00:00:00 2001 From: Alex Hall Date: Wed, 27 Dec 2023 14:19:56 +0200 Subject: [PATCH] (core) API console Summary: Adds a custom interactive Swagger API console at `/apiconsole`. For now, this isn't visibly linked anywhere. Test Plan: Manual, this is still an experimental and private feature. The idea is to merge this soon so that we have a chance to try it out in production. Reviewers: georgegevoian Reviewed By: georgegevoian Differential Revision: https://phab.getgrist.com/D4151 --- app/client/ui/Tools.ts | 11 ++ app/server/lib/AppEndpoint.ts | 3 + static/apiconsole.html | 220 ++++++++++++++++++++++++++++++++++ 3 files changed, 234 insertions(+) create mode 100644 static/apiconsole.html diff --git a/app/client/ui/Tools.ts b/app/client/ui/Tools.ts index 1ca56d8f..26a85638 100644 --- a/app/client/ui/Tools.ts +++ b/app/client/ui/Tools.ts @@ -100,6 +100,17 @@ export function tools(owner: Disposable, gristDoc: GristDoc, leftPanelOpen: Obse testId('settings'), ), cssSpacer(), + // TODO make this look nice, then make it visible when the console is ready. + // For now let's keep it private, so this shouldn't be uncommented. + // cssPageEntry( + // cssPageLink( + // cssPageIcon('Code'), + // cssPageIcon('FieldLink'), + // cssLinkText(t("API Console")), + // {href: window.origin + '/apiconsole', target: '_blank'} + // ), + // testId('api'), + // ), dom.maybe(docPageModel.currentDoc, (doc) => { const ex = buildExamples().find(e => e.urlId === doc.urlId); if (!ex || !ex.tutorialUrl) { return null; } diff --git a/app/server/lib/AppEndpoint.ts b/app/server/lib/AppEndpoint.ts index 4f40ada7..313d8ce3 100644 --- a/app/server/lib/AppEndpoint.ts +++ b/app/server/lib/AppEndpoint.ts @@ -44,6 +44,9 @@ export function attachAppEndpoint(options: AttachOptions): void { app.get(['/', '/ws/:wsId', '/p/:page'], ...middleware, expressWrap(async (req, res) => sendAppPage(req, res, {path: 'app.html', status: 200, config: {plugins}, googleTagManager: 'anon'}))); + app.get('/apiconsole', expressWrap(async (req, res) => + sendAppPage(req, res, {path: 'apiconsole.html', status: 200, config: {}}))); + app.get('/api/worker/:assignmentId([^/]+)/?*', expressWrap(async (req, res) => { if (!useWorkerPool()) { // Let the client know there is not a separate pool of workers, diff --git a/static/apiconsole.html b/static/apiconsole.html new file mode 100644 index 00000000..9191d3c5 --- /dev/null +++ b/static/apiconsole.html @@ -0,0 +1,220 @@ + + + + + + + Grist API Console + + + + +
+ + + +