Skip to content

Commit

Permalink
fixes path that does not start with slash issue by adding path checker
Browse files Browse the repository at this point in the history
  • Loading branch information
ahmetonurslmz committed May 8, 2021
1 parent 8808f94 commit aa76d91
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 3 deletions.
14 changes: 12 additions & 2 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,17 @@ const http = require('http');
const https = require('https');


const request = async ({ hostname, path, method = 'GET', payload = null }) => {
const pathChecker = (path) => {
if (path && path[0] === '/') {
return path;
} else if (path) {
return `/${path}`;
}
return '/';
};


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

const lib = isHttps ? https : http;
Expand All @@ -12,7 +22,7 @@ const request = async ({ hostname, path, method = 'GET', payload = null }) => {
method,
hostname: domain,
port: isHttps ? 443 : 80,
path: path || '/',
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.0.6",
"version": "1.0.7",
"description": "Perform request with promise based client on NodeJS",
"main": "index.js",
"scripts": {
Expand Down

0 comments on commit aa76d91

Please sign in to comment.