diff --git a/package.json b/package.json index beddf9cab8..03c9b411fe 100644 --- a/package.json +++ b/package.json @@ -6,7 +6,6 @@ }, "scripts": { "start": "yarn workspace example-app start", - "start:backend": "yarn workspace example-backend start", "bundle": "yarn build && yarn workspace example-app bundle", "build": "lerna run build", "clean": "lerna run clean", diff --git a/packages/app/package.json b/packages/app/package.json index e88bd46a54..8e75937fd8 100644 --- a/packages/app/package.json +++ b/packages/app/package.json @@ -4,7 +4,6 @@ "private": true, "devDependencies": { "@testing-library/cypress": "^6.0.0", - "@types/jquery": "^3.3.34", "@testing-library/jest-dom": "^4.2.4", "@testing-library/react": "^9.3.2", "@testing-library/user-event": "^7.1.2", @@ -15,13 +14,13 @@ "cross-env": "^7.0.0", "cypress": "^4.2.0", "eslint-plugin-cypress": "^2.10.3", + "http-proxy-middleware": "^1.0.3", "start-server-and-test": "^1.10.11" }, "dependencies": { "@backstage/cli": "^0.1.1-alpha.4", "@backstage/core": "^0.1.1-alpha.4", "@backstage/plugin-circleci": "^0.1.1-alpha.4", - "@backstage/plugin-circleci-backend": "^0.1.1-alpha.4", "@backstage/plugin-home-page": "^0.1.1-alpha.4", "@backstage/plugin-inventory": "^0.1.1-alpha.4", "@backstage/plugin-lighthouse": "^0.1.1-alpha.4", diff --git a/packages/app/src/setupProxy.js b/packages/app/src/setupProxy.js new file mode 100644 index 0000000000..65ed973923 --- /dev/null +++ b/packages/app/src/setupProxy.js @@ -0,0 +1,7 @@ +const { proxySettings } = require('@backstage/plugin-circleci'); +const { createProxyMiddleware } = require('http-proxy-middleware'); + +module.exports = (/** @type {import('express').Application} */ app) => + Object.entries(proxySettings).forEach(([url, settings]) => + app.use(url, createProxyMiddleware(settings)), + ); diff --git a/packages/backend/package.json b/packages/backend/package.json index 13d64a0a13..0530f04452 100644 --- a/packages/backend/package.json +++ b/packages/backend/package.json @@ -16,7 +16,6 @@ }, "dependencies": { "@backstage/plugin-inventory-backend": "0.1.1-alpha.4", - "@backstage/plugin-circleci-backend": "0.1.1-alpha.4", "compression": "^1.7.4", "cors": "^2.8.5", "express": "^4.17.1", diff --git a/packages/backend/src/index.ts b/packages/backend/src/index.ts index da1a4f3dc3..fd8015c328 100644 --- a/packages/backend/src/index.ts +++ b/packages/backend/src/index.ts @@ -28,7 +28,6 @@ import helmet from 'helmet'; import compression from 'compression'; import { testRouter } from './test'; import { router as inventoryRouter } from '@backstage/plugin-inventory-backend'; -import { router as circleCIRouter } from '@backstage/plugin-circleci-backend'; const DEFAULT_PORT = 7000; @@ -41,7 +40,6 @@ app.use(compression()); app.use(express.json()); app.use('/test', testRouter); app.use('/inventory', inventoryRouter); -app.use('/circleci', circleCIRouter); app.listen(PORT, () => { console.log(`Listening on port ${PORT}`); diff --git a/plugins/circleci-backend/.eslintrc.js b/plugins/circleci-backend/.eslintrc.js deleted file mode 100644 index 13573efa9c..0000000000 --- a/plugins/circleci-backend/.eslintrc.js +++ /dev/null @@ -1,3 +0,0 @@ -module.exports = { - extends: [require.resolve('@backstage/cli/config/eslint')], -}; diff --git a/plugins/circleci-backend/README.md b/plugins/circleci-backend/README.md deleted file mode 100644 index 91e60e3e6b..0000000000 --- a/plugins/circleci-backend/README.md +++ /dev/null @@ -1,6 +0,0 @@ -# Title -Welcome to the circleci-backend plugin! - -## Sub-section 1 - -## Sub-section 2 diff --git a/plugins/circleci-backend/package.json b/plugins/circleci-backend/package.json deleted file mode 100644 index 6535deba10..0000000000 --- a/plugins/circleci-backend/package.json +++ /dev/null @@ -1,23 +0,0 @@ -{ - "name": "@backstage/plugin-circleci-backend", - "version": "0.1.1-alpha.4", - "main": "dist", - "license": "Apache-2.0", - "private": true, - "scripts": { - "build": "tsc", - "lint": "backstage-cli lint", - "test": "backstage-cli test", - "clean": "backstage-cli clean" - }, - "devDependencies": { - "@backstage/cli": "^0.1.1-alpha.4" - }, - "dependencies": { - "express": "^4.17.1", - "http-proxy-middleware": "^1.0.3" - }, - "files": [ - "dist" - ] -} diff --git a/plugins/circleci-backend/src/index.ts b/plugins/circleci-backend/src/index.ts deleted file mode 100644 index 45bf47b884..0000000000 --- a/plugins/circleci-backend/src/index.ts +++ /dev/null @@ -1,27 +0,0 @@ -/* - * Copyright 2020 Spotify AB - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -import express from 'express'; -import httpProxy from 'http-proxy'; - -// Simple proxy for handling CORS for now -const proxy = httpProxy.createServer({ - target: 'https://circleci.com/api/v1.1', - changeOrigin: true, -}); -proxy.on('error', e => console.error(e)); -export const router = express(); -router.use('/api', (req, res) => proxy.web(req, res)); diff --git a/plugins/circleci-backend/tsconfig.json b/plugins/circleci-backend/tsconfig.json deleted file mode 100644 index b463ac102f..0000000000 --- a/plugins/circleci-backend/tsconfig.json +++ /dev/null @@ -1,15 +0,0 @@ -{ - "include": ["src"], - "compilerOptions": { - "baseUrl": "src", - "outDir": "dist", - "incremental": true, - "sourceMap": true, - "declaration": true, - "strict": true, - "target": "es5", - "module": "commonjs", - "esModuleInterop": true, - "types": ["node", "jest"] - } -} diff --git a/plugins/circleci/src/api/index.ts b/plugins/circleci/src/api/index.ts index 955daf3fba..afbd74f28f 100644 --- a/plugins/circleci/src/api/index.ts +++ b/plugins/circleci/src/api/index.ts @@ -18,7 +18,7 @@ import { CircleCI, GitType, CircleCIOptions } from 'circleci-api'; import { ApiRef } from '@backstage/core'; const defaultOptions: Partial = { - circleHost: 'http://backstage.localhost:7000/circleci/api', + circleHost: '/circleci/api', vcs: { type: GitType.GITHUB, owner: 'CircleCITest3', diff --git a/plugins/circleci/src/index.ts b/plugins/circleci/src/index.ts index d67bc6a864..33b8fe0067 100644 --- a/plugins/circleci/src/index.ts +++ b/plugins/circleci/src/index.ts @@ -16,3 +16,4 @@ export { plugin } from './plugin'; export * from './api'; +export * from './proxy'; diff --git a/plugins/circleci/src/plugin.ts b/plugins/circleci/src/plugin.ts index 05d3710d40..458a7f27bc 100644 --- a/plugins/circleci/src/plugin.ts +++ b/plugins/circleci/src/plugin.ts @@ -15,10 +15,12 @@ */ import { createPlugin } from '@backstage/core'; import { CircleCIPage } from './components/CircleCIPage'; +import { SettingsPage } from './components/SettingsPage'; export const plugin = createPlugin({ id: 'circleci', register({ router }) { - router.registerRoute('/circleci', CircleCIPage, { exact: false }); + router.registerRoute('/circleci', CircleCIPage); + router.registerRoute('/circleci/settings', SettingsPage); }, }); diff --git a/plugins/circleci/src/proxy.ts b/plugins/circleci/src/proxy.ts new file mode 100644 index 0000000000..397b9b3c56 --- /dev/null +++ b/plugins/circleci/src/proxy.ts @@ -0,0 +1,12 @@ +import type {Options} from 'http-proxy-middleware'; + +export const proxySettings: Record = { + '/circleci/api': { + target: 'https://circleci.com/api/v1.1', + changeOrigin: true, + logLevel: 'debug', + pathRewrite: { + '^/circleci/api/': '/', + }, + }, +}; diff --git a/yarn.lock b/yarn.lock index b3b8467ce5..d337b98883 100644 --- a/yarn.lock +++ b/yarn.lock @@ -4072,13 +4072,6 @@ dependencies: "@types/sizzle" "*" -"@types/jquery@^3.3.34": - version "3.3.34" - resolved "https://registry.npmjs.org/@types/jquery/-/jquery-3.3.34.tgz#0d3b94057063d3854adaeb579652048fec07ba6c" - integrity sha512-lW9vsVL53Xu/Nj4gi2hNmHGc4u3KKghjqTkAlO0kF5GIOPxbqqnQpgqJBzmn3yXLrPqHb6cmNJ6URnS23Vtvbg== - dependencies: - "@types/sizzle" "*" - "@types/js-cookie@2.2.5": version "2.2.5" resolved "https://registry.npmjs.org/@types/js-cookie/-/js-cookie-2.2.5.tgz#38dfaacae8623b37cc0b0d27398e574e3fc28b1e"