...
 
Commits (4)
const app = require('express')();
const bodyParser = require('body-parser');
const proxy = require('express-http-proxy');
app.use(bodyParser.urlencoded({ extended: true }));
app.use(bodyParser.json());
......@@ -19,6 +20,43 @@ app.use(bodyParser.json());
*/
app.use('/api/v1/ping', require('./ping'));
/**
* @api {get} /api/v1/project/:project_id/articles List articles
* @apiVersion 1.0.0
* @apiDescription Implement the GET /project/:project_id/articles API endpoint
* @apiName List articles
* @apiGroup Utils
*
* @apiSuccess {String} id ID of the file
* @apiSuccess {String} name Name of the file
* @apiSuccess {String} type Type of the file
* @apiSuccess {String} path Path of the file
* @apiSuccess {String} mode Mode of the file
*
* @apiSuccessExample Success-Response:
* HTTP/1.1 200 OK
* [
* {
* "id": "fc798eff13af1df4a91dc14d26b22c95a90e717d",
* "name": "Article_1.md",
* "type": "blob",
* "path": "Article_1.md",
* "mode": "100644"
* }
* ]
*/
app.get('/api/v1/project/:project_id/articles', proxy('localhost:8000', {
proxyReqPathResolver: (req) => {
return '/admin/api/v4/projects/' + req.params.project_id + '/repository/tree'
},
userResDecorator: (proxyRes, proxyResData, userRaq, userReq) => {
var data = JSON.parse(proxyResData.toString('utf8'));
data = data.filter((e) => e.name.endsWith('.md'));
return JSON.stringify(data);
}
}));
app.listen(3001, () => {
console.log('API server listening on port 3001')
});