diff --git a/src/main/webui/package-lock.json b/src/main/webui/package-lock.json index 655dbb9..9aca4dc 100644 --- a/src/main/webui/package-lock.json +++ b/src/main/webui/package-lock.json @@ -29,6 +29,7 @@ "@testing-library/jest-dom": "^6.1.4", "@testing-library/react": "^14.0.0", "babel-loader": "^9.1.3", + "body-parser": "^1.20.2", "css-loader": "^6.8.1", "eslint": "^8.51.0", "eslint-plugin-jest": "^27.6.0", @@ -4840,13 +4841,13 @@ } }, "node_modules/body-parser": { - "version": "1.20.1", - "resolved": "https://registry.npmjs.org/body-parser/-/body-parser-1.20.1.tgz", - "integrity": "sha512-jWi7abTbYwajOytWCQc37VulmWiRae5RyTpaCyDcS5/lMdtwSz5lOpDE67srw/HYe35f1z3fDQw+3txg7gNtWw==", + "version": "1.20.2", + "resolved": "https://registry.npmjs.org/body-parser/-/body-parser-1.20.2.tgz", + "integrity": "sha512-ml9pReCu3M61kGlqoTm2umSXTlRTuGTx0bfYj+uIUKKYycG5NtSbeetV3faSU6R7ajOPw0g/J1PvK4qNy7s5bA==", "dev": true, "dependencies": { "bytes": "3.1.2", - "content-type": "~1.0.4", + "content-type": "~1.0.5", "debug": "2.6.9", "depd": "2.0.0", "destroy": "1.2.0", @@ -4854,7 +4855,7 @@ "iconv-lite": "0.4.24", "on-finished": "2.4.1", "qs": "6.11.0", - "raw-body": "2.5.1", + "raw-body": "2.5.2", "type-is": "~1.6.18", "unpipe": "1.0.0" }, @@ -6821,6 +6822,54 @@ "integrity": "sha512-PCVAQswWemu6UdxsDFFX/+gVeYqKAod3D3UVm91jHwynguOwAvYPhx8nNlM++NqRcK6CxxpUafjmhIdKiHibqg==", "dev": true }, + "node_modules/express/node_modules/body-parser": { + "version": "1.20.1", + "resolved": "https://registry.npmjs.org/body-parser/-/body-parser-1.20.1.tgz", + "integrity": "sha512-jWi7abTbYwajOytWCQc37VulmWiRae5RyTpaCyDcS5/lMdtwSz5lOpDE67srw/HYe35f1z3fDQw+3txg7gNtWw==", + "dev": true, + "dependencies": { + "bytes": "3.1.2", + "content-type": "~1.0.4", + "debug": "2.6.9", + "depd": "2.0.0", + "destroy": "1.2.0", + "http-errors": "2.0.0", + "iconv-lite": "0.4.24", + "on-finished": "2.4.1", + "qs": "6.11.0", + "raw-body": "2.5.1", + "type-is": "~1.6.18", + "unpipe": "1.0.0" + }, + "engines": { + "node": ">= 0.8", + "npm": "1.2.8000 || >= 1.4.16" + } + }, + "node_modules/express/node_modules/bytes": { + "version": "3.1.2", + "resolved": "https://registry.npmjs.org/bytes/-/bytes-3.1.2.tgz", + "integrity": "sha512-/Nf7TyzTx6S3yRJObOAV7956r8cr2+Oj8AC5dt8wSP3BQAoeX58NoHyCU8P8zGkNXStjTSi6fzO6F0pBdcYbEg==", + "dev": true, + "engines": { + "node": ">= 0.8" + } + }, + "node_modules/express/node_modules/raw-body": { + "version": "2.5.1", + "resolved": "https://registry.npmjs.org/raw-body/-/raw-body-2.5.1.tgz", + "integrity": "sha512-qqJBtEyVgS0ZmPGdCFPWJ3FreoqvG4MVQln/kCgF7Olq95IbOp0/BWyMwbdtn4VTvkM8Y7khCQ2Xgk/tcrCXig==", + "dev": true, + "dependencies": { + "bytes": "3.1.2", + "http-errors": "2.0.0", + "iconv-lite": "0.4.24", + "unpipe": "1.0.0" + }, + "engines": { + "node": ">= 0.8" + } + }, "node_modules/express/node_modules/safe-buffer": { "version": "5.2.1", "resolved": "https://registry.npmjs.org/safe-buffer/-/safe-buffer-5.2.1.tgz", @@ -11711,9 +11760,9 @@ } }, "node_modules/raw-body": { - "version": "2.5.1", - "resolved": "https://registry.npmjs.org/raw-body/-/raw-body-2.5.1.tgz", - "integrity": "sha512-qqJBtEyVgS0ZmPGdCFPWJ3FreoqvG4MVQln/kCgF7Olq95IbOp0/BWyMwbdtn4VTvkM8Y7khCQ2Xgk/tcrCXig==", + "version": "2.5.2", + "resolved": "https://registry.npmjs.org/raw-body/-/raw-body-2.5.2.tgz", + "integrity": "sha512-8zGqypfENjCIqGhgXToC8aB2r7YrBX+AQAfIPs/Mlk+BtPTztOvTS01NRW/3Eh60J+a48lt8qsCzirQ6loCVfA==", "dev": true, "dependencies": { "bytes": "3.1.2", diff --git a/src/main/webui/package.json b/src/main/webui/package.json index 6673d90..9fc7c23 100644 --- a/src/main/webui/package.json +++ b/src/main/webui/package.json @@ -26,6 +26,7 @@ "@testing-library/jest-dom": "^6.1.4", "@testing-library/react": "^14.0.0", "babel-loader": "^9.1.3", + "body-parser": "^1.20.2", "css-loader": "^6.8.1", "eslint": "^8.51.0", "eslint-plugin-jest": "^27.6.0", diff --git a/src/main/webui/src/server/app.js b/src/main/webui/src/server/app.js index ec19bad..23f4300 100644 --- a/src/main/webui/src/server/app.js +++ b/src/main/webui/src/server/app.js @@ -1,5 +1,6 @@ import compression from 'compression'; import express from 'express'; +import bodyParser from 'body-parser'; import path from 'path'; import {Config} from './config/AppConfig'; @@ -8,6 +9,8 @@ const indexHtml=path.join(projectRoot+'/index.html'); const app = express(); app.use(compression()); +app.use(bodyParser.urlencoded({extended: true})); +app.use(bodyParser.json({extended: true})); const server = app.listen(Config.SERVER_PORT, () => { const host = server.address().address; const port = server.address().port; @@ -98,3 +101,38 @@ app.get('/api/admin/stores/maven/group/:name', (req, res) => { res.status(400).json({error: "Missing store name"}); } }); + +const newFakeRepo = (packageType, type, name)=>{ + const storeKey = `${packageType}:${type}:${name}`; + const repo = { + "packageType": `${packageType}`, + "type": `${type}`, + "name": `${name}`, + "key": `${storeKey}`, + "description": `This is a fake repo for ${storeKey}`, + "disabled": false, + "disable_timeout": 0, + "path_style": "plain", + "authoritative_index": false, + "prepend_constituent": false + }; + return repo; +}; + +app.post('/api/admin/stores/:packageType/:type/:name', (req, res) => { + const [packageType, type, name]=[req.params.packageType, req.params.type, req.params.name]; + console.log(packageType, type, name); + const repoBody = req.body; + console.log(repoBody); + const responseRepo = newFakeRepo(packageType, type, name); + if (responseRepo){ + res.status(204).json(responseRepo); + }else{ + res.status(400).json({error: "Bad repo request"}); + } +}); + +app.put('/api/admin/stores/:packageType/:type/:name', (req, res) => { + // TODO: need to implement +}); +