I tried to do it but I gave up… yeaIs it possible to when you call example, https:api.domain.com/createfile/(+ data) it creates a file in that server in folder I want to if so how?
It’s a javascript file that I want also make work and start process of it. (npm run) it.
Assuming that you have root access on your server.
Initialization steps:
npm install express should do the trickWhat the express server may look like by now:
const express = require('express');
const shell = require('shelljs')
const app = express();
app.post('/createfile/:data', async function (req, res) {
if (!req || !req.params || !req.params.data ) {
return res.status(400).send("Malformed url");
}
// I assume the data in the paramas is the url to the git repo
const giturl = req.params.data;
// You should probably lightly check the url to make sure its a valid one on the surface level.
const path = 'absolute/path/to/folder'
if (!shell.which('git')) {
shell.echo('Sorry, this script requires git');
shell.exit(1);
return res.status(400).send("Not supported");
}
shell.cd(path)
shell.exec('git clone ' + giturl, function (code, stdout, stderr) {
console.log('Exit code:', code);
console.log('Program output:', stdout);
console.log('Program stderr:', stderr);
if (code === 0)
return res.status(200).send("Success");
else
return res.status(400).send("Issue with clone")
});
});
const server = await app.listen(3000);