Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

179
Visualizações
Rest Api to clone repository from git

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.

about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

Assuming that you have root access on your server.

Initialization steps:

  1. Install node.js on your machine
  2. Create a new node project and install Express npm install express should do the trick
  3. Setup a basic http server and now you must make decisions on how to field the requests
    1. If you plan to run everything over regular http then you can probably just have the node server listen on port 80 of your machine. (Really should run https)
    2. If you want to run https (and thus have a domain name) then I would take the time to setup nginx to listen to port 80 (to redirect to 443) and 443 (TLS port) and then have it serve as a reverse proxy for the express server. Thus the node server could just run on localhost:3000 for example. (If you want a free certificate for SSL you can use let's encrypt with nginx)
    3. My Suggestion: Use nginx as a reverse proxy either way
  4. Setup your request endpoint, a post request endpoint for example.
  5. There are a few ways to clone a repo through node, using shelljs is one way.

What 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);
about 4 years ago · Juan Pablo Isaza Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda