Skip to content

Commit

Permalink
Merge pull request #68 from ligangty/2.0-refactor
Browse files Browse the repository at this point in the history
Add post for store operation in mock testing server
  • Loading branch information
ligangty authored Nov 13, 2023
2 parents 7c7d475 + 72e94a2 commit bee3129
Show file tree
Hide file tree
Showing 3 changed files with 96 additions and 8 deletions.
65 changes: 57 additions & 8 deletions src/main/webui/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions src/main/webui/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
38 changes: 38 additions & 0 deletions src/main/webui/src/server/app.js
Original file line number Diff line number Diff line change
@@ -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';

Expand All @@ -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;
Expand Down Expand Up @@ -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
});

0 comments on commit bee3129

Please sign in to comment.