diff --git a/src/main/webui/package-lock.json b/src/main/webui/package-lock.json index 9aca4dc..9d395a3 100644 --- a/src/main/webui/package-lock.json +++ b/src/main/webui/package-lock.json @@ -29,7 +29,6 @@ "@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,39 +4839,6 @@ "node": ">=8" } }, - "node_modules/body-parser": { - "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.5", - "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.2", - "type-is": "~1.6.18", - "unpipe": "1.0.0" - }, - "engines": { - "node": ">= 0.8", - "npm": "1.2.8000 || >= 1.4.16" - } - }, - "node_modules/body-parser/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/bonjour-service": { "version": "1.1.0", "resolved": "https://registry.npmjs.org/bonjour-service/-/bonjour-service-1.1.0.tgz", @@ -11759,30 +11725,6 @@ "node": ">= 0.6" } }, - "node_modules/raw-body": { - "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", - "http-errors": "2.0.0", - "iconv-lite": "0.4.24", - "unpipe": "1.0.0" - }, - "engines": { - "node": ">= 0.8" - } - }, - "node_modules/raw-body/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/react": { "version": "18.2.0", "resolved": "https://registry.npmjs.org/react/-/react-18.2.0.tgz", diff --git a/src/main/webui/package.json b/src/main/webui/package.json index 9fc7c23..6673d90 100644 --- a/src/main/webui/package.json +++ b/src/main/webui/package.json @@ -26,7 +26,6 @@ "@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 23f4300..4807a54 100644 --- a/src/main/webui/src/server/app.js +++ b/src/main/webui/src/server/app.js @@ -1,6 +1,5 @@ import compression from 'compression'; import express from 'express'; -import bodyParser from 'body-parser'; import path from 'path'; import {Config} from './config/AppConfig'; @@ -9,8 +8,7 @@ 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})); +app.use(express.json()); const server = app.listen(Config.SERVER_PORT, () => { const host = server.address().address; const port = server.address().port; @@ -102,37 +100,47 @@ app.get('/api/admin/stores/maven/group/:name', (req, res) => { } }); -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; -}; +// 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); + const newRepo = req.body; + if(req.headers['content-type']==="application/json"){ + if (newRepo.packageType&&newRepo.type&&newRepo.name){ + // res.status(204); + res.sendStatus(204); + }else{ + res.status(400).json({error: "Bad repo request: missing packageType or type or name for repo!"}); + } }else{ - res.status(400).json({error: "Bad repo request"}); + res.status(400).json({error: "Bad request: wrong header content-type"}); } }); app.put('/api/admin/stores/:packageType/:type/:name', (req, res) => { - // TODO: need to implement + const updatedRepo = req.body; + if(req.headers['content-type']==="application/json"){ + if (updatedRepo.packageType&&updatedRepo.type&&updatedRepo.name){ + res.status(200).json(updatedRepo); + }else{ + res.status(400).json({error: "Bad repo request: missing packageType or type or name for repo!"}); + } + }else{ + res.status(400).json({error: "Bad request: wrong header content-type"}); + } });