mirror of https://github.com/embarklabs/embark.git
fix(modules/pipeline): ensure REST file API parses query parameters
Data send from the client with GET parameters are serialized in the request body's `params` property. As express doesn't seem to parse those, we have to do it manually to perform object property traversals.
This commit is contained in:
parent
b654fdecd8
commit
064b2da5a4
|
@ -28,12 +28,14 @@ class Pipeline {
|
|||
'get',
|
||||
'/embark-api/file',
|
||||
(req, res) => {
|
||||
if (!fs.existsSync(req.query.path) || !req.query.path.startsWith(fs.dappPath())) {
|
||||
const queryParams = JSON.parse(req.query.params);
|
||||
|
||||
if (!fs.existsSync(queryParams.path) || !queryParams.path.startsWith(fs.dappPath())) {
|
||||
return res.send({error: 'Path is invalid'});
|
||||
}
|
||||
const name = path.basename(req.query.path);
|
||||
const content = fs.readFileSync(req.query.path, 'utf8');
|
||||
res.send({name, content, path: req.query.path});
|
||||
const name = path.basename(queryParams.path);
|
||||
const content = fs.readFileSync(queryParams.path, 'utf8');
|
||||
res.send({name, content, path: queryParams.path});
|
||||
|
||||
}
|
||||
);
|
||||
|
|
Loading…
Reference in New Issue