step 1 : setting konfigurasi
This commit is contained in:
3
node_modules/axios-curlirize/.babelrc
generated
vendored
Normal file
3
node_modules/axios-curlirize/.babelrc
generated
vendored
Normal file
@@ -0,0 +1,3 @@
|
||||
{
|
||||
"presets": ["env"]
|
||||
}
|
||||
14
node_modules/axios-curlirize/.eslintrc.yml
generated
vendored
Normal file
14
node_modules/axios-curlirize/.eslintrc.yml
generated
vendored
Normal file
@@ -0,0 +1,14 @@
|
||||
env:
|
||||
mocha: true
|
||||
browser: true
|
||||
es2021: true
|
||||
extends: 'eslint:recommended'
|
||||
parserOptions:
|
||||
ecmaVersion: 12
|
||||
sourceType: module
|
||||
rules: {
|
||||
no-prototype-builtins: 'off',
|
||||
no-console: 'off',
|
||||
no-undefined: 'off',
|
||||
no-undef: 'off',
|
||||
}
|
||||
21
node_modules/axios-curlirize/LICENSE
generated
vendored
Normal file
21
node_modules/axios-curlirize/LICENSE
generated
vendored
Normal file
@@ -0,0 +1,21 @@
|
||||
MIT License
|
||||
|
||||
Copyright (c) 2018 Delirius325
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all
|
||||
copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
SOFTWARE.
|
||||
107
node_modules/axios-curlirize/README.md
generated
vendored
Normal file
107
node_modules/axios-curlirize/README.md
generated
vendored
Normal file
@@ -0,0 +1,107 @@
|
||||
[](https://app.codacy.com/app/antho325/axios-curlirize?utm_source=github.com&utm_medium=referral&utm_content=delirius325/axios-curlirize&utm_campaign=Badge_Grade_Dashboard)
|
||||
[](https://circleci.com/gh/delirius325/axios-curlirize)
|
||||
[](https://badge.fury.io/js/axios-curlirize)
|
||||
|
||||
# Description
|
||||
|
||||
This module is an axios third-party module to log any axios request as a curl command in the console. It was originally posted as a suggestion on the axios repository, but since we believed it wasn't in the scope of axios to release such feature, we decided to make it as an independent module.
|
||||
|
||||
# How it works
|
||||
|
||||
The module makes use of axios' interceptors to log the request as a cURL command. It also stores it in the response's config object. Therefore, the command can be seen in the app's console, as well as in the `res.config.curlCommand` property of the response.
|
||||
|
||||
# Changing the logger
|
||||
|
||||
By default, axios-curlirize uses the `console.log/error()` functions. It is possible to change the logger by doing something similar to this:
|
||||
|
||||
```javascript
|
||||
// when initiating your curlirize instance
|
||||
curlirize(axios, (result, err) => {
|
||||
const { command } = result;
|
||||
if (err) {
|
||||
// use your logger here
|
||||
} else {
|
||||
// use your logger here
|
||||
}
|
||||
});
|
||||
```
|
||||
|
||||
# How to use it
|
||||
|
||||
axios-curlirize is super easy to use. First you'll have to install it.
|
||||
|
||||
```shell
|
||||
npm i --save axios-curlirize@latest
|
||||
```
|
||||
|
||||
Then all you have to do is import and instanciate curlirize in your app. Here's a sample:
|
||||
|
||||
```javascript
|
||||
import axios from 'axios';
|
||||
import express from 'express';
|
||||
import curlirize from 'axios-curlirize';
|
||||
|
||||
const app = express();
|
||||
|
||||
// initializing axios-curlirize with your axios instance
|
||||
curlirize(axios);
|
||||
|
||||
// creating dummy route
|
||||
app.post('/', (req, res) => {
|
||||
res.send({ hello: 'world!' });
|
||||
});
|
||||
|
||||
// starting server
|
||||
app.listen(7500, () => {
|
||||
console.log('Dummy server started on port 7500');
|
||||
/*
|
||||
The output of this in the console will be :
|
||||
curl -X POST -H "Content-Type:application/x-www-form-urlencoded" --data {"dummy":"data"} http://localhost:7500/
|
||||
*/
|
||||
axios
|
||||
.post('http://localhost:7500/', { dummy: 'data' })
|
||||
.then(res => {
|
||||
console.log('success');
|
||||
})
|
||||
.catch(err => {
|
||||
console.log(err);
|
||||
});
|
||||
});
|
||||
```
|
||||
|
||||
## Curilirize additional axios instance
|
||||
To curlirize any other instances of axios (aside from the base one), please call the `curlirize()` method on that instance.
|
||||
```javascript
|
||||
const instance = axios.create({ baseURL: 'https://some-domain.com/api/', timeout: 1000, headers: {'X-Custom-Header': 'foobar'} });
|
||||
curlirize(instance);
|
||||
```
|
||||
|
||||
# Disable the logger
|
||||
|
||||
By default, all requests will be logged. But you can disable this behaviour unitarily by setting the `curlirize` option to false within the axios request.
|
||||
|
||||
```javascript
|
||||
axios
|
||||
.post('http://localhost:7500/', { dummy: 'data' }, {
|
||||
curlirize: false
|
||||
})
|
||||
.then(res => {
|
||||
console.log('success');
|
||||
})
|
||||
.catch(err => {
|
||||
console.log(err);
|
||||
});
|
||||
```
|
||||
|
||||
# Clear a request
|
||||
|
||||
```javascript
|
||||
axios
|
||||
.post('http://localhost:7500/', { dummy: 'data' })
|
||||
.then(res => {
|
||||
res.config.clearCurl();
|
||||
})
|
||||
.catch(err => {
|
||||
console.log(err);
|
||||
});
|
||||
```
|
||||
74
node_modules/axios-curlirize/mb.log
generated
vendored
Normal file
74
node_modules/axios-curlirize/mb.log
generated
vendored
Normal file
@@ -0,0 +1,74 @@
|
||||
{"message":"[mb:2525] mountebank v2.4.0 now taking orders - point your browser to http://localhost:2525/ for help","level":"info","timestamp":"2021-07-06T18:01:07.333Z"}
|
||||
{"message":"[mb:2525] POST /imposters","level":"info","timestamp":"2021-07-06T18:04:47.389Z"}
|
||||
{"message":"[http:8080] Open for business...","level":"info","timestamp":"2021-07-06T18:04:47.421Z"}
|
||||
{"message":"[mb:2525] GET /images/book.jpg","level":"info","timestamp":"2021-07-06T18:04:52.013Z"}
|
||||
{"message":"[http:8080] ::1:64745 => GET //branches?_end=10&_order=ASC&_sort=id&_start=0","level":"info","timestamp":"2021-07-06T18:05:10.330Z"}
|
||||
{"message":"[http:8080] no predicate match, using default response","level":"info","timestamp":"2021-07-06T18:05:10.345Z"}
|
||||
{"message":"[http:8080] ::1:64746 => GET /favicon.ico","level":"info","timestamp":"2021-07-06T18:05:10.454Z"}
|
||||
{"message":"[http:8080] no predicate match, using default response","level":"info","timestamp":"2021-07-06T18:05:10.457Z"}
|
||||
{"message":"[http:8080] ::1:64747 => GET /branches?_end=10&_order=ASC&_sort=id&_start=0","level":"info","timestamp":"2021-07-06T18:05:14.077Z"}
|
||||
{"message":"[http:8080] no predicate match, using default response","level":"info","timestamp":"2021-07-06T18:05:14.080Z"}
|
||||
{"message":"[http:8080] ::1:64748 => GET /favicon.ico","level":"info","timestamp":"2021-07-06T18:05:14.112Z"}
|
||||
{"message":"[http:8080] no predicate match, using default response","level":"info","timestamp":"2021-07-06T18:05:14.113Z"}
|
||||
{"message":"[mb:2525] POST /imposters","level":"info","timestamp":"2021-07-06T18:05:38.342Z"}
|
||||
{"message":"[mb:2525] error creating imposter: {\"code\":\"EADDRINUSE\",\"errno\":-48,\"syscall\":\"listen\",\"address\":\"::\",\"port\":8080,\"domainEmitter\":{\"_events\":{\"connection\":[null,null]},\"_eventsCount\":3,\"_connections\":0,\"_handle\":null,\"_usingWorkers\":false,\"_workers\":[],\"_unref\":false,\"allowHalfOpen\":true,\"pauseOnConnect\":false,\"httpAllowHalfOpen\":false,\"timeout\":0,\"keepAliveTimeout\":5000,\"maxHeadersCount\":null,\"headersTimeout\":60000,\"requestTimeout\":0},\"domainThrown\":false,\"message\":\"listen EADDRINUSE: address already in use :::8080\",\"name\":\"Error\",\"stack\":\"Error: listen EADDRINUSE: address already in use :::8080\\n at Server.setupListenHandle [as _listen2] (node:net:1310:16)\\n at listenInCluster (node:net:1358:12)\\n at Server.listen (node:net:1445:7)\\n at create (/usr/local/lib/node_modules/mountebank/src/models/http/baseHttpServer.js:143:16)\\n at Object.createServer (/usr/local/lib/node_modules/mountebank/src/models/protocols.js:23:13)\\n at Domain.<anonymous> (/usr/local/lib/node_modules/mountebank/src/models/imposter.js:204:18)\\n at Domain.run (node:domain:373:15)\\n at Object.create (/usr/local/lib/node_modules/mountebank/src/models/imposter.js:199:12)\\n at createImposter (/usr/local/lib/node_modules/mountebank/src/models/protocols.js:156:25)\\n at Object.result.<computed>.createImposterFrom (/usr/local/lib/node_modules/mountebank/src/models/protocols.js:163:61)\"}","level":"error","timestamp":"2021-07-06T18:05:38.349Z"}
|
||||
{"message":"[mb:2525] GET /images/book.jpg","level":"info","timestamp":"2021-07-06T18:05:41.967Z"}
|
||||
{"message":"[mb:2525] GET /images/book.jpg","level":"info","timestamp":"2021-07-06T18:05:43.634Z"}
|
||||
{"message":"[mb:2525] DELETE /imposters","level":"info","timestamp":"2021-07-06T18:05:57.036Z"}
|
||||
{"message":"[http:8080] Ciao for now","level":"info","timestamp":"2021-07-06T18:05:57.039Z"}
|
||||
{"message":"[mb:2525] POST /imposters","level":"info","timestamp":"2021-07-06T18:06:02.019Z"}
|
||||
{"message":"[http:8080] Open for business...","level":"info","timestamp":"2021-07-06T18:06:02.023Z"}
|
||||
{"message":"[mb:2525] GET /images/book.jpg","level":"info","timestamp":"2021-07-06T18:06:03.191Z"}
|
||||
{"message":"[http:8080] ::1:64770 => GET /branches?_end=10&_order=ASC&_sort=id&_start=0","level":"info","timestamp":"2021-07-06T18:06:04.713Z"}
|
||||
{"message":"[http:8080] no predicate match, using default response","level":"info","timestamp":"2021-07-06T18:06:04.717Z"}
|
||||
{"message":"[http:8080] ::1:64771 => GET /favicon.ico","level":"info","timestamp":"2021-07-06T18:06:04.754Z"}
|
||||
{"message":"[http:8080] no predicate match, using default response","level":"info","timestamp":"2021-07-06T18:06:04.756Z"}
|
||||
{"message":"[http:8080] ::1:64772 => GET /branches?_end=10&_order=ASC&_sort=id&_start=0","level":"info","timestamp":"2021-07-06T18:06:08.540Z"}
|
||||
{"message":"[http:8080] no predicate match, using default response","level":"info","timestamp":"2021-07-06T18:06:08.543Z"}
|
||||
{"message":"[http:8080] ::1:64773 => GET /favicon.ico","level":"info","timestamp":"2021-07-06T18:06:08.581Z"}
|
||||
{"message":"[http:8080] no predicate match, using default response","level":"info","timestamp":"2021-07-06T18:06:08.583Z"}
|
||||
{"message":"[http:8080] ::1:64782 => GET /branches?_end=10&_order=ASC&_sort=id&_start=0","level":"info","timestamp":"2021-07-06T18:06:12.397Z"}
|
||||
{"message":"[http:8080] no predicate match, using default response","level":"info","timestamp":"2021-07-06T18:06:12.400Z"}
|
||||
{"message":"[http:8080] ::1:64783 => GET /favicon.ico","level":"info","timestamp":"2021-07-06T18:06:12.464Z"}
|
||||
{"message":"[http:8080] no predicate match, using default response","level":"info","timestamp":"2021-07-06T18:06:12.466Z"}
|
||||
{"message":"[mb:2525] DELETE /imposters","level":"info","timestamp":"2021-07-06T18:06:31.147Z"}
|
||||
{"message":"[http:8080] Ciao for now","level":"info","timestamp":"2021-07-06T18:06:31.148Z"}
|
||||
{"message":"[mb:2525] GET /images/book.jpg","level":"info","timestamp":"2021-07-06T18:08:14.487Z"}
|
||||
{"message":"[mb:2525] POST /imposters","level":"info","timestamp":"2021-07-06T18:09:51.463Z"}
|
||||
{"message":"[http:8080] Open for business...","level":"info","timestamp":"2021-07-06T18:09:51.466Z"}
|
||||
{"message":"[http:8080] ::1:49345 => GET /branches?_end=10&_order=ASC&_sort=id&_start=0","level":"info","timestamp":"2021-07-06T18:09:56.198Z"}
|
||||
{"message":"[http:8080] no predicate match, using default response","level":"info","timestamp":"2021-07-06T18:09:56.201Z"}
|
||||
{"message":"[http:8080] ::1:49346 => GET /favicon.ico","level":"info","timestamp":"2021-07-06T18:09:56.321Z"}
|
||||
{"message":"[http:8080] no predicate match, using default response","level":"info","timestamp":"2021-07-06T18:09:56.324Z"}
|
||||
{"message":"[mb:2525] GET /images/book.jpg","level":"info","timestamp":"2021-07-06T18:10:14.770Z"}
|
||||
{"message":"[mb:2525] GET /images/book.jpg","level":"info","timestamp":"2021-07-06T18:10:15.514Z"}
|
||||
{"message":"[mb:2525] GET /imposters/8080/stubs/0","level":"info","timestamp":"2021-07-06T18:10:27.097Z"}
|
||||
{"message":"[http:8080] ::1:49427 => GET /branches?_end=10&_order=ASC&_sort=id&_start=0","level":"info","timestamp":"2021-07-06T18:10:48.079Z"}
|
||||
{"message":"[http:8080] no predicate match, using default response","level":"info","timestamp":"2021-07-06T18:10:48.080Z"}
|
||||
{"message":"[mb:2525] POST /imposters","level":"info","timestamp":"2021-07-06T18:12:16.959Z"}
|
||||
{"message":"[mb:2525] error creating imposter: {\"code\":\"EADDRINUSE\",\"errno\":-48,\"syscall\":\"listen\",\"address\":\"::\",\"port\":8080,\"domainEmitter\":{\"_events\":{\"connection\":[null,null]},\"_eventsCount\":3,\"_connections\":0,\"_handle\":null,\"_usingWorkers\":false,\"_workers\":[],\"_unref\":false,\"allowHalfOpen\":true,\"pauseOnConnect\":false,\"httpAllowHalfOpen\":false,\"timeout\":0,\"keepAliveTimeout\":5000,\"maxHeadersCount\":null,\"headersTimeout\":60000,\"requestTimeout\":0},\"domainThrown\":false,\"message\":\"listen EADDRINUSE: address already in use :::8080\",\"name\":\"Error\",\"stack\":\"Error: listen EADDRINUSE: address already in use :::8080\\n at Server.setupListenHandle [as _listen2] (node:net:1310:16)\\n at listenInCluster (node:net:1358:12)\\n at Server.listen (node:net:1445:7)\\n at create (/usr/local/lib/node_modules/mountebank/src/models/http/baseHttpServer.js:143:16)\\n at Object.createServer (/usr/local/lib/node_modules/mountebank/src/models/protocols.js:23:13)\\n at Domain.<anonymous> (/usr/local/lib/node_modules/mountebank/src/models/imposter.js:204:18)\\n at Domain.run (node:domain:373:15)\\n at Object.create (/usr/local/lib/node_modules/mountebank/src/models/imposter.js:199:12)\\n at createImposter (/usr/local/lib/node_modules/mountebank/src/models/protocols.js:156:25)\\n at Object.result.<computed>.createImposterFrom (/usr/local/lib/node_modules/mountebank/src/models/protocols.js:163:61)\"}","level":"error","timestamp":"2021-07-06T18:12:16.962Z"}
|
||||
{"message":"[mb:2525] DELETE /imposters","level":"info","timestamp":"2021-07-06T18:12:19.061Z"}
|
||||
{"message":"[http:8080] Ciao for now","level":"info","timestamp":"2021-07-06T18:12:19.063Z"}
|
||||
{"message":"[mb:2525] POST /imposters","level":"info","timestamp":"2021-07-06T18:12:20.701Z"}
|
||||
{"message":"[http:8080] Open for business...","level":"info","timestamp":"2021-07-06T18:12:20.705Z"}
|
||||
{"message":"[http:8080] ::1:49453 => GET /branches?_end=10&_order=ASC&_sort=id&_start=0","level":"info","timestamp":"2021-07-06T18:12:28.059Z"}
|
||||
{"message":"[http:8080] no predicate match, using default response","level":"info","timestamp":"2021-07-06T18:12:28.062Z"}
|
||||
{"message":"[http:8080] ::1:49455 => GET /branches?_end=10&_order=ASC&_sort=id&_start=0","level":"info","timestamp":"2021-07-06T18:12:29.718Z"}
|
||||
{"message":"[http:8080] no predicate match, using default response","level":"info","timestamp":"2021-07-06T18:12:29.722Z"}
|
||||
{"message":"[http:8080] ::1:49457 => GET /branches?_end=10&_order=ASC&_sort=id&_start=0","level":"info","timestamp":"2021-07-06T18:12:30.412Z"}
|
||||
{"message":"[http:8080] no predicate match, using default response","level":"info","timestamp":"2021-07-06T18:12:30.414Z"}
|
||||
{"message":"[mb:2525] GET /images/book.jpg","level":"info","timestamp":"2021-07-06T18:12:33.042Z"}
|
||||
{"message":"[mb:2525] GET /images/book.jpg","level":"info","timestamp":"2021-07-06T18:12:50.214Z"}
|
||||
{"message":"[mb:2525] DELETE /imposters","level":"info","timestamp":"2021-07-06T18:13:37.558Z"}
|
||||
{"message":"[http:8080] Ciao for now","level":"info","timestamp":"2021-07-06T18:13:37.559Z"}
|
||||
{"message":"[mb:2525] DELETE /imposters","level":"info","timestamp":"2021-07-06T18:14:47.749Z"}
|
||||
{"message":"[mb:2525] POST /imposters","level":"info","timestamp":"2021-07-06T18:14:51.079Z"}
|
||||
{"message":"[http:8080] Open for business...","level":"info","timestamp":"2021-07-06T18:14:51.081Z"}
|
||||
{"message":"[http:8080] ::1:49476 => GET /branches?_end=10&_order=ASC&_sort=id&_start=0","level":"info","timestamp":"2021-07-06T18:15:01.463Z"}
|
||||
{"message":"[mb:2525] DELETE /imposters","level":"info","timestamp":"2021-07-06T18:16:16.617Z"}
|
||||
{"message":"[http:8080] Ciao for now","level":"info","timestamp":"2021-07-06T18:16:16.618Z"}
|
||||
{"message":"[mb:2525] POST /imposters","level":"info","timestamp":"2021-07-06T18:16:19.249Z"}
|
||||
{"message":"[http:8080] Open for business...","level":"info","timestamp":"2021-07-06T18:16:19.252Z"}
|
||||
{"message":"[http:8080] ::1:49486 => GET /branches?_end=10&_order=ASC&_sort=id&_start=0","level":"info","timestamp":"2021-07-06T18:16:24.654Z"}
|
||||
{"message":"[mb:2525] GET /images/book.jpg","level":"info","timestamp":"2021-07-06T18:23:26.451Z"}
|
||||
{"message":"[mb:2525] Adios - see you soon?","level":"info","timestamp":"2021-07-06T18:38:20.335Z"}
|
||||
49
node_modules/axios-curlirize/package.json
generated
vendored
Normal file
49
node_modules/axios-curlirize/package.json
generated
vendored
Normal file
@@ -0,0 +1,49 @@
|
||||
{
|
||||
"name": "axios-curlirize",
|
||||
"version": "2.0.0",
|
||||
"description": "Axios third-party module to print all axios requests as curl commands in the console. This repository is forked from axios-curlirize <https://www.npmjs.com/package/axios-curlirize> and supports use with Node JS without having to enable ES6 imports. This repo was inspired by an issue <https://github.com/delirius325/axios-curlirize/issues/20> raised on the origional repository <https://github.com/delirius325/axios-curlirize>. Special thanks to Anthony Gauthier <https://github.com/delirius325>, the author of axios-curlirize",
|
||||
"main": "src/main.js",
|
||||
"type": "module",
|
||||
"scripts": {
|
||||
"test": "./node_modules/mocha/bin/mocha --recursive --exit tests/**/*.spec.js*"
|
||||
},
|
||||
"repository": {
|
||||
"type": "git",
|
||||
"url": "git+https://github.com/delirius325/axios-curlirize.git"
|
||||
},
|
||||
"keywords": [
|
||||
"axios",
|
||||
"curl",
|
||||
"debug"
|
||||
],
|
||||
"author": "delirius325",
|
||||
"contributors": [
|
||||
{
|
||||
"name": "Justin \"jayceekay\"",
|
||||
"url": "https://github.com/jayceekay"
|
||||
},
|
||||
{
|
||||
"name": "Peter \"binggg\" Zhao",
|
||||
"url": "https://github.com/binggg"
|
||||
},
|
||||
{
|
||||
"name": "Abhishek Rajeshirke <arajeshirke79@gmail.com>",
|
||||
"url": "https://github.com/colidarity"
|
||||
}
|
||||
],
|
||||
"license": "MIT",
|
||||
"bugs": {
|
||||
"url": "https://github.com/delirius325/axios-curlirize/issues"
|
||||
},
|
||||
"homepage": "https://github.com/delirius325/axios-curlirize#readme",
|
||||
"dependencies": {
|
||||
},
|
||||
"devDependencies": {
|
||||
"axios": ">=0.21.1",
|
||||
"eslint": "^7.29.0",
|
||||
"expect": "^27.0.6",
|
||||
"express": "^4.17.1",
|
||||
"mocha": "^9.0.1",
|
||||
"qs": "^6.9.4"
|
||||
}
|
||||
}
|
||||
109
node_modules/axios-curlirize/src/lib/CurlHelper.js
generated
vendored
Normal file
109
node_modules/axios-curlirize/src/lib/CurlHelper.js
generated
vendored
Normal file
@@ -0,0 +1,109 @@
|
||||
export class CurlHelper {
|
||||
constructor(config) {
|
||||
this.request = config;
|
||||
}
|
||||
|
||||
getHeaders() {
|
||||
let headers = this.request.headers,
|
||||
curlHeaders = "";
|
||||
|
||||
// get the headers concerning the appropriate method (defined in the global axios instance)
|
||||
if (headers.hasOwnProperty("common")) {
|
||||
headers = this.request.headers[this.request.method];
|
||||
}
|
||||
|
||||
// add any custom headers (defined upon calling methods like .get(), .post(), etc.)
|
||||
for(let property in this.request.headers) {
|
||||
if (
|
||||
!["common", "delete", "get", "head", "patch", "post", "put"].includes(
|
||||
property
|
||||
)
|
||||
) {
|
||||
headers[property] = this.request.headers[property];
|
||||
}
|
||||
}
|
||||
|
||||
for(let property in headers) {
|
||||
if({}.hasOwnProperty.call(headers, property)) {
|
||||
let header = `${property}:${headers[property]}`;
|
||||
curlHeaders = `${curlHeaders} -H "${header}"`;
|
||||
}
|
||||
}
|
||||
|
||||
return curlHeaders.trim();
|
||||
}
|
||||
|
||||
getMethod() {
|
||||
return `-X ${this.request.method.toUpperCase()}`;
|
||||
}
|
||||
|
||||
getBody() {
|
||||
if (
|
||||
typeof this.request.data !== "undefined" &&
|
||||
this.request.data !== "" &&
|
||||
this.request.data !== null &&
|
||||
this.request.method.toUpperCase() !== "GET"
|
||||
) {
|
||||
let data =
|
||||
typeof this.request.data === "object" ||
|
||||
Object.prototype.toString.call(this.request.data) === "[object Array]"
|
||||
? JSON.stringify(this.request.data)
|
||||
: this.request.data;
|
||||
return `--data '${data}'`.trim();
|
||||
} else {
|
||||
return "";
|
||||
}
|
||||
}
|
||||
|
||||
getUrl() {
|
||||
if (this.request.baseURL) {
|
||||
let baseUrl = this.request.baseURL
|
||||
let url = this.request.url
|
||||
let finalUrl = baseUrl + "/" + url
|
||||
return finalUrl
|
||||
.replace(/\/{2,}/g, '/')
|
||||
.replace("http:/", "http://")
|
||||
.replace("https:/", "https://")
|
||||
}
|
||||
return this.request.url;
|
||||
}
|
||||
|
||||
getQueryString() {
|
||||
if (this.request.paramsSerializer) {
|
||||
const params = this.request.paramsSerializer(this.request.params)
|
||||
if (!params || params.length === 0) return ''
|
||||
if (params.startsWith('?')) return params
|
||||
return `?${params}`
|
||||
}
|
||||
let params = ""
|
||||
let i = 0
|
||||
|
||||
for(let param in this.request.params) {
|
||||
if({}.hasOwnProperty.call(this.request.params, param)) {
|
||||
params +=
|
||||
i !== 0
|
||||
? `&${param}=${this.request.params[param]}`
|
||||
: `?${param}=${this.request.params[param]}`;
|
||||
i++;
|
||||
}
|
||||
}
|
||||
|
||||
return params;
|
||||
}
|
||||
|
||||
getBuiltURL() {
|
||||
let url = this.getUrl();
|
||||
|
||||
if (this.getQueryString() !== "") {
|
||||
url += this.getQueryString();
|
||||
}
|
||||
|
||||
return url.trim();
|
||||
}
|
||||
|
||||
generateCommand() {
|
||||
return `curl ${this.getMethod()} "${this.getBuiltURL()}" ${this.getHeaders()} ${this.getBody()}`
|
||||
.trim()
|
||||
.replace(/\s{2,}/g, " ");
|
||||
}
|
||||
}
|
||||
37
node_modules/axios-curlirize/src/main.js
generated
vendored
Normal file
37
node_modules/axios-curlirize/src/main.js
generated
vendored
Normal file
@@ -0,0 +1,37 @@
|
||||
import { CurlHelper } from "./lib/CurlHelper.js";
|
||||
|
||||
function defaultLogCallback(curlResult, err) {
|
||||
const { command } = curlResult;
|
||||
if (err) {
|
||||
console.error(err);
|
||||
} else {
|
||||
console.info(command);
|
||||
}
|
||||
}
|
||||
|
||||
export default (instance, callback = defaultLogCallback) => {
|
||||
instance.interceptors.request.use((req) => {
|
||||
try {
|
||||
const curl = new CurlHelper(req);
|
||||
req.curlObject = curl;
|
||||
req.curlCommand = curl.generateCommand();
|
||||
req.clearCurl = () => {
|
||||
delete req.curlObject;
|
||||
delete req.curlCommand;
|
||||
delete req.clearCurl;
|
||||
};
|
||||
} catch (err) {
|
||||
// Even if the axios middleware is stopped, no error should occur outside.
|
||||
callback(null, err);
|
||||
} finally {
|
||||
if (req.curlirize !== false) {
|
||||
callback({
|
||||
command: req.curlCommand,
|
||||
object: req.curlObject
|
||||
});
|
||||
}
|
||||
return req;
|
||||
}
|
||||
});
|
||||
};
|
||||
|
||||
264
node_modules/axios-curlirize/tests/curlirize.spec.js
generated
vendored
Normal file
264
node_modules/axios-curlirize/tests/curlirize.spec.js
generated
vendored
Normal file
@@ -0,0 +1,264 @@
|
||||
import expect from "expect";
|
||||
import axios from "axios";
|
||||
import curlirize from "../src/main.js";
|
||||
import { CurlHelper } from "../src/lib/CurlHelper.js";
|
||||
import qs from 'qs'
|
||||
import app from "./devapp.js";
|
||||
|
||||
curlirize(axios);
|
||||
|
||||
describe("Testing curlirize", () => {
|
||||
it("should return a 200 with the value 'world'", (done) => {
|
||||
axios.post("http://localhost:7500/", { dummy: "data" })
|
||||
.then((res) => {
|
||||
expect(res.status).toBe(200);
|
||||
expect(res.data.hello).toBe("world");
|
||||
done();
|
||||
})
|
||||
.catch((err) => {
|
||||
console.error(err);
|
||||
});
|
||||
});
|
||||
it("should allow to remove curlirize part on a request", (done) => {
|
||||
axios.post("http://localhost:7500/", { dummy: "data" })
|
||||
.then((res) => {
|
||||
expect(res.status).toBe(200);
|
||||
expect(res.data.hello).toBe("world");
|
||||
res.config.clearCurl();
|
||||
expect(res.config.curlObject).not.toBeDefined();
|
||||
expect(res.config.curlCommand).not.toBeDefined();
|
||||
expect(res.config.clearCurl).not.toBeDefined();
|
||||
done();
|
||||
})
|
||||
.catch((err) => {
|
||||
console.error(err);
|
||||
});
|
||||
});
|
||||
|
||||
it("should return a generated command with XML as data", (done) => {
|
||||
axios.post("http://localhost:7500", "<myTestTag></myTestTag>")
|
||||
.then((res) => {
|
||||
expect(res.config.curlObject.getBody()).toBe("--data '<myTestTag></myTestTag>'");
|
||||
expect(res.config.curlCommand).toContain("<myTestTag></myTestTag>");
|
||||
done();
|
||||
})
|
||||
.catch((err) => {
|
||||
console.error(err);
|
||||
});
|
||||
});
|
||||
|
||||
it("should return the response with the defined curl command", (done) => {
|
||||
axios.post("http://localhost:7500/", { dummy: "data" })
|
||||
.then((res) => {
|
||||
expect(res.config.curlCommand).toBeDefined();
|
||||
expect(res.config.curlCommand).toBe(`curl -X POST "http://localhost:7500/" -H "Content-Type:application/x-www-form-urlencoded" --data '{"dummy":"data"}'`);
|
||||
done();
|
||||
})
|
||||
.catch((err) => {
|
||||
console.error(err);
|
||||
});
|
||||
});
|
||||
|
||||
it("should return the generated command with no --data attribute", (done) => {
|
||||
axios.post("http://localhost:7500/")
|
||||
.then((res) => {
|
||||
expect(res.config.curlCommand).toBeDefined();
|
||||
expect(res.config.curlCommand).toBe(`curl -X POST "http://localhost:7500/" -H "Content-Type:application/x-www-form-urlencoded"`);
|
||||
done();
|
||||
})
|
||||
.catch((err) => {
|
||||
console.error(err);
|
||||
});
|
||||
});
|
||||
|
||||
it("should return the generated command with headers specified on method call", (done) => {
|
||||
axios.post("http://localhost:7500/", null, {headers: {Authorization: "Bearer 123", testHeader: "Testing"}})
|
||||
.then((res) => {
|
||||
expect(res.config.curlCommand).toBeDefined();
|
||||
expect(res.config.curlCommand).toBe('curl -X POST "http://localhost:7500/" -H "Content-Type:application/x-www-form-urlencoded" -H "Authorization:Bearer 123" -H "testHeader:Testing"');
|
||||
done();
|
||||
})
|
||||
.catch((err) => {
|
||||
console.error(err);
|
||||
});
|
||||
});
|
||||
|
||||
it("should return the generated command with a queryString specified in the URL", (done) => {
|
||||
axios.post("http://localhost:7500/", null, {params: {test: 1}})
|
||||
.then((res) => {
|
||||
expect(res.config.curlCommand).toBeDefined();
|
||||
expect(res.config.curlCommand).toBe('curl -X POST "http://localhost:7500/?test=1" -H "Content-Type:application/x-www-form-urlencoded"');
|
||||
done();
|
||||
})
|
||||
.catch((err) => {
|
||||
console.error(err);
|
||||
});
|
||||
});
|
||||
|
||||
it("should return the generated command with a queryString specified in the URL with paramsSerializer", (done) => {
|
||||
const api = axios.create({
|
||||
paramsSerializer: (params) => {
|
||||
return qs.stringify(params)
|
||||
}
|
||||
})
|
||||
curlirize(api)
|
||||
api.post("http://localhost:7500/", null, {params: {test: 1, text: 'sim'}})
|
||||
.then((res) => {
|
||||
expect(res.config.curlCommand).toBeDefined();
|
||||
expect(res.config.curlCommand).toBe('curl -X POST "http://localhost:7500/?test=1&text=sim" -H "Content-Type:application/x-www-form-urlencoded"');
|
||||
done();
|
||||
})
|
||||
.catch((err) => {
|
||||
console.error(err);
|
||||
});
|
||||
});
|
||||
|
||||
it("do not add ? if params is empty", (done) => {
|
||||
axios.post("http://localhost:7500/", null)
|
||||
.then((res) => {
|
||||
expect(res.config.curlCommand).toBeDefined();
|
||||
expect(res.config.curlCommand).toBe('curl -X POST "http://localhost:7500/" -H "Content-Type:application/x-www-form-urlencoded"');
|
||||
done();
|
||||
})
|
||||
.catch((err) => {
|
||||
console.log('--', err)
|
||||
console.error(err);
|
||||
});
|
||||
});
|
||||
|
||||
it("do not cut end slash", (done) => {
|
||||
const api = axios.create({
|
||||
baseURL: 'http://localhost:7500',
|
||||
})
|
||||
curlirize(api)
|
||||
api.post("api/", null, {params: {test: 1, text: 'sim'}})
|
||||
.then((res) => {
|
||||
expect(res.config.curlCommand).toBeDefined();
|
||||
expect(res.config.curlCommand).toBe('curl -X POST "http://localhost:7500/api/?test=1&text=sim" -H "Content-Type:application/x-www-form-urlencoded"');
|
||||
done();
|
||||
})
|
||||
.catch((err) => {
|
||||
console.error(err);
|
||||
});
|
||||
});
|
||||
|
||||
it("cut middle slash", (done) => {
|
||||
const api = axios.create({
|
||||
baseURL: 'http://localhost:7500/',
|
||||
})
|
||||
curlirize(api)
|
||||
api.post("/api/", null, {params: {test: 1, text: 'sim'}})
|
||||
.then((res) => {
|
||||
expect(res.config.curlCommand).toBeDefined();
|
||||
expect(res.config.curlCommand).toBe('curl -X POST "http://localhost:7500/api/?test=1&text=sim" -H "Content-Type:application/x-www-form-urlencoded"');
|
||||
done();
|
||||
})
|
||||
.catch((err) => {
|
||||
console.error(err);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
describe("Testing curl-helper module", () => {
|
||||
const fakeConfig = {
|
||||
adapter: () => { return "dummy"; },
|
||||
transformRequest: { "0": () => { return "dummy"; } },
|
||||
transformResponse: { "0": () => { return "dummy"; } },
|
||||
timeout: 0,
|
||||
xsrfCookieName: "XSRF-TOKEN",
|
||||
xsrfHeaderName: "X-XSRF-TOKEN",
|
||||
maxContentLength: -1,
|
||||
validateStatus: () => { return "dummy"; },
|
||||
headers: { Accept: "application/json, text/plain, */*", "Content-Type": "application/json;charset=utf-8" },
|
||||
method: "post",
|
||||
url: "http://localhost:7500/",
|
||||
data: { dummy: "data" },
|
||||
params: { testParam: "test1", testParamTwo: "test2"}
|
||||
};
|
||||
const curl = new CurlHelper(fakeConfig);
|
||||
|
||||
it("should return an empty string if data is undefined", (done) => {
|
||||
let emptyConfig = {
|
||||
adapter: () => { return "dummy" },
|
||||
transformRequest: { "0": () => { return "dummy" } },
|
||||
transformResponse: { "0": () => { return "dummy" } },
|
||||
timeout: 0,
|
||||
xsrfCookieName: "XSRF-TOKEN",
|
||||
xsrfHeaderName: "X-XSRF-TOKEN",
|
||||
maxContentLength: -1,
|
||||
validateStatus: () => { return "dummy" },
|
||||
headers: { Accept: "application/json, text/plain, */*", "Content-Type": "application/json;charset=utf-8" },
|
||||
method: "post",
|
||||
url: "http://localhost:7500/",
|
||||
data: undefined
|
||||
};
|
||||
const emptyDataCurl = new CurlHelper(emptyConfig);
|
||||
expect(emptyDataCurl.getBody()).toBe("");
|
||||
done();
|
||||
});
|
||||
|
||||
it("should return an empty string if data is == empty string", (done) => {
|
||||
let emptyConfig = {
|
||||
adapter: () => { return "dummy" },
|
||||
transformRequest: { "0": () => { return "dummy" } },
|
||||
transformResponse: { "0": () => { return "dummy" } },
|
||||
timeout: 0,
|
||||
xsrfCookieName: "XSRF-TOKEN",
|
||||
xsrfHeaderName: "X-XSRF-TOKEN",
|
||||
maxContentLength: -1,
|
||||
validateStatus: () => { return "dummy" },
|
||||
headers: { Accept: "application/json, text/plain, */*", "Content-Type": "application/json;charset=utf-8" },
|
||||
method: "post",
|
||||
url: "http://localhost:7500/",
|
||||
data: ""
|
||||
};
|
||||
const emptyDataCurl = new CurlHelper(emptyConfig);
|
||||
expect(emptyDataCurl.getBody()).toBe('');
|
||||
done();
|
||||
});
|
||||
|
||||
it("should return {} as --data if req data is == {}", (done) => {
|
||||
let emptyConfig = {
|
||||
adapter: () => { return "dummy" },
|
||||
transformRequest: { "0": () => { return "dummy" } },
|
||||
transformResponse: { "0": () => { return "dummy" } },
|
||||
timeout: 0,
|
||||
xsrfCookieName: "XSRF-TOKEN",
|
||||
xsrfHeaderName: "X-XSRF-TOKEN",
|
||||
maxContentLength: -1,
|
||||
validateStatus: () => { return "dummy" },
|
||||
headers: { Accept: "application/json, text/plain, */*", "Content-Type": "application/json;charset=utf-8" },
|
||||
method: "post",
|
||||
url: "http://localhost:7500/",
|
||||
data: {}
|
||||
};
|
||||
const emptyDataCurl = new CurlHelper(emptyConfig);
|
||||
expect(emptyDataCurl.getBody()).toBe("--data '{}'");
|
||||
done();
|
||||
});
|
||||
|
||||
it("should return a string with headers", (done) => {
|
||||
expect(curl.getHeaders()).toBe("-H \"Accept:application/json, text/plain, */*\" -H \"Content-Type:application/json;charset=utf-8\"");
|
||||
done();
|
||||
});
|
||||
|
||||
it("should return a string with HTTP method", (done) => {
|
||||
expect(curl.getMethod()).toBe("-X POST");
|
||||
done();
|
||||
});
|
||||
|
||||
it("should return a string with request body", (done) => {
|
||||
expect(curl.getBody()).toBe(`--data '{"dummy":"data"}'`);
|
||||
done();
|
||||
});
|
||||
|
||||
it("should return the URL of the request", (done) => {
|
||||
expect(curl.getUrl()).toBe("http://localhost:7500/");
|
||||
done();
|
||||
});
|
||||
|
||||
it("should return the queryString of the request", (done) => {
|
||||
expect(curl.getQueryString()).toBe("?testParam=test1&testParamTwo=test2");
|
||||
done();
|
||||
});
|
||||
});
|
||||
21
node_modules/axios-curlirize/tests/devapp.js
generated
vendored
Normal file
21
node_modules/axios-curlirize/tests/devapp.js
generated
vendored
Normal file
@@ -0,0 +1,21 @@
|
||||
import express from "express";
|
||||
|
||||
const app = express();
|
||||
|
||||
app.get("/", (req, res) => {
|
||||
res.send({ hello: "world" });
|
||||
});
|
||||
|
||||
app.post("/", (req, res) => {
|
||||
res.send({ hello: "world" });
|
||||
});
|
||||
|
||||
app.post("/api", (req, res) => {
|
||||
res.send({ hello: "world" });
|
||||
});
|
||||
|
||||
app.listen(7500, () => {
|
||||
console.info("Express dev server listening on port 7500");
|
||||
});
|
||||
|
||||
export default app;
|
||||
Reference in New Issue
Block a user