Skip to content

Commit

Permalink
uses modern url parser instead of hard-coded functions and adds local…
Browse files Browse the repository at this point in the history
…host port support
  • Loading branch information
ahmetonurslmz committed Feb 12, 2022
1 parent 051e023 commit ef03364
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 5 deletions.
8 changes: 4 additions & 4 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,15 +13,15 @@ const pathChecker = (path) => {


const request = async ({ hostname, path = '/', method = 'GET', payload = null, isJson = false, headers = {} }) => {
const isHttps = hostname.startsWith('https://');
const urlParts = new URL(hostname);

const isHttps = urlParts.protocol === 'https:';
const lib = isHttps ? https : http;
const domain = hostname.split('://')[1];

const options = {
method,
hostname: domain,
port: isHttps ? 443 : 80,
hostname: urlParts.hostname,
port: (urlParts.port || (isHttps ? 443 : 80)),
path: pathChecker(path),
headers: {
'User-Agent': 'AOS',
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "smoothly-request",
"version": "1.1.3",
"version": "1.1.4",
"description": "Perform request with promise based client on NodeJS",
"main": "index.js",
"scripts": {
Expand Down

0 comments on commit ef03364

Please sign in to comment.