[ Web Proxy ]
URL:
Viewing: https://raw.githubusercontent.com/hlambda/hlambda-cli/v0.0.12/src/utils/executeShellCommandClass.js [Back]  [Original]

import fetch from 'node-fetch';

export const executeShellCommandClass =
  (adminSecret, endpoint, silent = false) =>
  async (command, cwd) => {
    const headers = {
      'x-hlambda-admin-secret': adminSecret,
      Accept: 'application/json',
      'Content-Type': 'application/json', // Important
    };
    const response = await fetch(`${endpoint}/console/api/v1/command-request`, {
      method: 'POST',
      // Important
      body: JSON.stringify({
        command,
        cwd,
      }),
      headers,
    });

    if (!silent) {
      if (response.status === 200) {
        console.log(`Shell command`.green, `${command}`.red, `executed!`.green);
      }
      console.log(response.status);
    }

    return response;
  };

export default executeShellCommandClass;

Web Proxy Viewer  |  New URL  |  Original Page