Last active
December 10, 2022 07:52
-
-
Save M1n007/a43b90a92f117c0546b2a511337ec8b4 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const { CurlGenerator } = require('curl-generator'); | |
const { exec } = require('child_process'); | |
const createCurlCommand = (url, method, headers, body) => { | |
const params = { | |
url, | |
method, | |
headers | |
} | |
if (body) params.body = body | |
const generateCommand = CurlGenerator(params, { compressed: true }) | |
return generateCommand.replace('curl', '') | |
} | |
const execCommand = (command) => new Promise((resolve, reject) => { | |
exec(command, (err, stdout, stderr) => { | |
if (err) { | |
reject(err, stderr) | |
} | |
resolve(stdout) | |
}); | |
}); | |
(async () => { | |
try { | |
const curlImperSonatePattern = 'docker run --rm lwthiker/curl-impersonate:0.5-chrome curl_chrome101'; | |
const headers = { | |
} | |
const curlGeneratorResult = createCurlCommand(encodeURI('https://jsonplaceholder.typicode.com/todos/1'), 'GET', headers, ''); | |
const resultCurl = await execCommand(`${curlImperSonatePattern} ${curlGeneratorResult}`) | |
console.log(resultCurl) | |
} catch (e) { | |
console.log(e) | |
} | |
})(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment