From 38de7d2904e47692f65198da7de85488684941f8 Mon Sep 17 00:00:00 2001 From: Jonathan Sick Date: Mon, 9 May 2022 12:07:13 -0400 Subject: [PATCH 1/8] Update package-lock version to 0.7.0 --- package-lock.json | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/package-lock.json b/package-lock.json index bb749574..e29b817f 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "squareone", - "version": "0.5.0", + "version": "0.7.0", "lockfileVersion": 2, "requires": true, "packages": { "": { "name": "squareone", - "version": "0.5.0", + "version": "0.7.0", "dependencies": { "@fontsource/source-sans-pro": "^4.5.9", "@fortawesome/fontawesome-svg-core": "^6.1.1", From 125ce102b846beef70911c8e3055721e71dcd484 Mon Sep 17 00:00:00 2001 From: Jonathan Sick Date: Mon, 9 May 2022 11:38:50 -0400 Subject: [PATCH 2/8] Add timesSquareUrl configuration This both configures the URL prefix for the Times Square API, and also enables/disables the feature. --- squareone.config.schema.json | 7 ++++++- squareone.config.yaml | 1 + 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/squareone.config.schema.json b/squareone.config.schema.json index 5aa1b60b..3e7e2e64 100644 --- a/squareone.config.schema.json +++ b/squareone.config.schema.json @@ -27,7 +27,12 @@ "semaphoreUrl": { "type": "string", "title": "Semaphore URL", - "description": "URL of the Semaphore API service for obtaining notifications and broadcasts" + "description": "URL prefix of the Semaphore API service for obtaining notifications and broadcasts. Does not end in /. Omit or set as null to disable Semaphore features." + }, + "timesSquareUrl": { + "type": "string", + "title": "Times Square API URL", + "description": "URL prefix of the Times Square API service. Does not end in /. Omit or set as null to disable the /times-square/ pages." } } } diff --git a/squareone.config.yaml b/squareone.config.yaml index 11f4ea8e..572fe093 100644 --- a/squareone.config.yaml +++ b/squareone.config.yaml @@ -3,3 +3,4 @@ baseUrl: 'http://localhost:3000' siteDescription: | The site description. semaphoreUrl: 'https://data-dev.lsst.cloud/semaphore' +timesSquareUrl: 'http://localhost:3000/times-square/api' From 3355ba95ce7c577ef53e22ff1cda3573994ff4d4 Mon Sep 17 00:00:00 2001 From: Jonathan Sick Date: Mon, 9 May 2022 11:56:47 -0400 Subject: [PATCH 3/8] Port mock times-square API routes These were originally developed at https://github.com/lsst-sqre/times-square-ui --- next.config.js | 18 ++++++++ src/pages/api/dev/times-square/v1/pages.js | 27 ++++++++++++ .../api/dev/times-square/v1/pages/[page].js | 43 +++++++++++++++++++ .../dev/times-square/v1/pages/[page]/html.js | 28 ++++++++++++ .../v1/pages/[page]/htmlstatus.js | 26 +++++++++++ 5 files changed, 142 insertions(+) create mode 100644 src/pages/api/dev/times-square/v1/pages.js create mode 100644 src/pages/api/dev/times-square/v1/pages/[page].js create mode 100644 src/pages/api/dev/times-square/v1/pages/[page]/html.js create mode 100644 src/pages/api/dev/times-square/v1/pages/[page]/htmlstatus.js diff --git a/next.config.js b/next.config.js index 3e62ecf7..d80b4c59 100644 --- a/next.config.js +++ b/next.config.js @@ -52,10 +52,28 @@ module.exports = (phase, { defaultConfig }) => { serverRuntimeConfig: { ...serverYamlConfig }, async rewrites() { return [ + // Mock Gafaelfawr (this is never triggered by a production ingress) { source: '/auth/api/v1/user-info', destination: '/api/dev/user-info', }, + // Mock Times Square (this is never triggered by a production ingress) + { + source: '/times-square/api/v1/pages', + destination: '/api/dev/times-square/v1/pages', + }, + { + source: '/times-square/api/v1/pages/:page/html', + destination: '/api/dev/times-square/v1/pages/:page/html', + }, + { + source: '/times-square/api/v1/pages/:page/htmlstatus', + destination: '/api/dev/times-square/v1/pages/:page/htmlstatus', + }, + { + source: '/times-square/api/v1/pages/:page', + destination: '/api/dev/times-square/v1/pages/:page', + }, ]; }, }; diff --git a/src/pages/api/dev/times-square/v1/pages.js b/src/pages/api/dev/times-square/v1/pages.js new file mode 100644 index 00000000..18f04af2 --- /dev/null +++ b/src/pages/api/dev/times-square/v1/pages.js @@ -0,0 +1,27 @@ +/* + * Mock Times Square API endpoint: /times-square/v1/pages + * + * This endpoint lists available pages. + */ + +import getConfig from 'next/config'; + +export default function handler(req, res) { + const { publicRuntimeConfig } = getConfig(); + const { timesSquareUrl } = publicRuntimeConfig; + + const createPage = (name) => { + const pageBaseUrl = `${timesSquareUrl}/v1/pages/${name}`; + return { + name, + title: name, + self_url: pageBaseUrl, + }; + }; + + const content = [createPage('mypage'), createPage('anotherpage')]; + + res.statusCode = 200; + res.setHeader('Content-Type', 'application/json'); + res.end(JSON.stringify(content)); +} diff --git a/src/pages/api/dev/times-square/v1/pages/[page].js b/src/pages/api/dev/times-square/v1/pages/[page].js new file mode 100644 index 00000000..26f63597 --- /dev/null +++ b/src/pages/api/dev/times-square/v1/pages/[page].js @@ -0,0 +1,43 @@ +/* + * Mock Times Square API endpoint: /times-square/v1/pages/:page + */ +import getConfig from 'next/config'; + +export default function handler(req, res) { + const { page } = req.query; + const { publicRuntimeConfig } = getConfig(); + const { timesSquareUrl } = publicRuntimeConfig; + const pageBaseUrl = `${timesSquareUrl}/v1/pages/${page}`; + + if (page == 'not-found') { + // simulate a page that doesn't exist in the backend + res.statusCode = 404; + res.end(); + return; + } + + const content = { + name: page, + self_url: pageBaseUrl, + source_url: `${pageBaseUrl}/source`, + rendered_url: `${pageBaseUrl}/rendered`, + html_url: `${pageBaseUrl}/html`, + html_status_url: `${pageBaseUrl}/htmlstatus`, + parameters: { + a: { + type: 'number', + default: 42, + description: 'A number.', + }, + b: { + type: 'string', + default: 'Hello', + description: 'A string.', + }, + }, + }; + + res.statusCode = 200; + res.setHeader('Content-Type', 'application/json'); + res.end(JSON.stringify(content)); +} diff --git a/src/pages/api/dev/times-square/v1/pages/[page]/html.js b/src/pages/api/dev/times-square/v1/pages/[page]/html.js new file mode 100644 index 00000000..a40fa9ff --- /dev/null +++ b/src/pages/api/dev/times-square/v1/pages/[page]/html.js @@ -0,0 +1,28 @@ +/* + * Mock Times Square API endpoint: /times-square/v1/pages/[page]/html + */ + +const htmlContent = ` + + + + + + Test document + + + +

Test content

+

Hello world

+ + +`; + +export default function handler(req, res) { + const { page } = req.query; + console.log(req.url); + + res.statusCode = 200; + res.setHeader('Content-Type', 'text/html'); + res.end(htmlContent); +} diff --git a/src/pages/api/dev/times-square/v1/pages/[page]/htmlstatus.js b/src/pages/api/dev/times-square/v1/pages/[page]/htmlstatus.js new file mode 100644 index 00000000..c2806287 --- /dev/null +++ b/src/pages/api/dev/times-square/v1/pages/[page]/htmlstatus.js @@ -0,0 +1,26 @@ +/* + * Mock Times Square API endpoint: /times-square/api/v1/pages/:page/htmlstatus + */ +import getConfig from 'next/config'; + +export default function handler(req, res) { + const { page, a } = req.query; + const { publicRuntimeConfig } = getConfig(); + const { timesSquareUrl } = publicRuntimeConfig; + + const pageBaseUrl = `${timesSquareUrl}/v1/pages/${page}`; + + const content = { + available: a != '2', // magic value to toggle status modes + html_url: `${pageBaseUrl}/html?a={a}`, + html_hash: a != '2' ? '12345' : null, + }; + + console.log(content); + + console.log('Pinged status'); + + res.statusCode = 200; + res.setHeader('Content-Type', 'application/json'); + res.end(JSON.stringify(content)); +} From a946e6ccef425a0bafbb48da8ab652790fd67fe5 Mon Sep 17 00:00:00 2001 From: Jonathan Sick Date: Mon, 9 May 2022 14:17:52 -0400 Subject: [PATCH 4/8] Make the main content layout chooseable Previously the content layout component was part of the Page component (that also provides the header and footer). Now each page can supply a getLayout property that returns the layout component that the page should use. For existing pages, I've made getLayout return the MainContent component. In the future we can push more into the component loaded by getLayout in order to have more variation in layouts for different parts of Squareone. For now, making the content layout choose able is sufficient for applications like making simple content pages have a different container than more special-purpose apps Times Square. --- src/components/Page/Page.js | 2 +- src/pages/_app.js | 6 +++++- src/pages/api-aspect.js | 6 ++++++ src/pages/docs.js | 5 +++++ src/pages/index.js | 5 +++++ src/pages/login.js | 6 ++++++ src/pages/logout.js | 6 ++++++ src/pages/support.js | 5 +++++ src/pages/terms.js | 6 ++++++ 9 files changed, 45 insertions(+), 2 deletions(-) diff --git a/src/components/Page/Page.js b/src/components/Page/Page.js index 1a0aa773..cb59487a 100644 --- a/src/components/Page/Page.js +++ b/src/components/Page/Page.js @@ -40,7 +40,7 @@ export default function Page({ children, semaphoreUrl }) {
- {children} + {children}