Skip to content

Commit 3c1f827

Browse files
committed
docs: update common issues with sample code
1 parent 9aa421d commit 3c1f827

File tree

2 files changed

+48
-9
lines changed

2 files changed

+48
-9
lines changed

COMMON_ISSUES.md

Lines changed: 42 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,46 @@
11
## Error: SSL peer certificate or SSH remote key was not Ok
22

3-
You need to set either [`CAINFO`](https://curl.haxx.se/libcurl/c/CURLOPT_CAINFO.html) or [`CAPATH`](https://curl.haxx.se/libcurl/c/CURLOPT_CAPATH.html) options, or disable SSL verification with [`SSL_VERIFYPEER`](https://curl.haxx.se/libcurl/c/CURLOPT_SSL_VERIFYPEER.html) which is not recommended.
3+
You need to set either [`CAINFO`](https://curl.haxx.se/libcurl/c/CURLOPT_CAINFO.html) or [`CAPATH`](https://curl.haxx.se/libcurl/c/CURLOPT_CAPATH.html) options, or disable SSL verification with [`SSL_VERIFYPEER`](https://curl.haxx.se/libcurl/c/CURLOPT_SSL_VERIFYPEER.html) (not recommended).
44

55
The certificate file can be obtained in multiple ways:
6-
1. Downloaded from https://curl.haxx.se/docs/caextract.html
7-
2. Creating a file with the contents of `tls.rootCertificates`, which was added with Node.js `v12.3.0`
6+
7+
1. Extracted directly from your system/browser
8+
2. Downloaded from https://curl.haxx.se/docs/caextract.html, which is based on the one from Firefox
9+
3. Creating a file with the contents of `tls.rootCertificates`, which was added with Node.js `v12.3.0`, example:
10+
```javascript
11+
const fs = require('fs')
12+
const path = require('path')
13+
const tls = require('tls')
14+
15+
const { curly } = require('node-libcurl')
16+
17+
// important steps
18+
const certFilePath = path.join(__dirname, 'cert.pem')
19+
const tlsData = tls.rootCertificates.join('\n')
20+
fs.writeFileSync(certFilePath, tlsData)
21+
22+
async function run() {
23+
return curly.post('https://httpbin.org/anything', {
24+
postFields: JSON.stringify({ a: 'b' }),
25+
httpHeader: ['Content-type: application/json'],
26+
caInfo: certFilePath,
27+
verbose: true,
28+
})
29+
}
30+
31+
run()
32+
.then(({ data, statusCode, headers }) =>
33+
console.log(
34+
require('util').inspect(
35+
{
36+
data: JSON.parse(data),
37+
statusCode,
38+
headers,
39+
},
40+
null,
41+
4,
42+
),
43+
),
44+
)
45+
.catch((error) => console.error(`Something went wrong`, { error }))
46+
```

README.md

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -41,9 +41,9 @@
4141
- [Setting HTTP headers](#setting-http-headers)
4242
- [Form Submission (Content-Type: application/x-www-form-urlencoded)](#form-submission-content-type-applicationx-www-form-urlencoded)
4343
- [MultiPart Upload / HttpPost libcurl Option (Content-Type: multipart/form-data)](#multipart-upload--httppost-libcurl-option-content-type-multipartform-data)
44-
- [Benchmarks](#benchmarks)
4544
- [API](#api)
4645
- [Common Issues](#common-issues)
46+
- [Benchmarks](#benchmarks)
4747
- [Supported Libcurl Versions](#supported-libcurl-versions)
4848
- [For Enterprise](#for-enterprise)
4949
- [Detailed Installation](#detailed-installation)
@@ -161,9 +161,6 @@ curl.on('error', close);
161161

162162
For more examples check the [examples folder](./examples).
163163

164-
## Benchmarks
165-
Go [here](./benchmark)
166-
167164
## API
168165

169166
The code provides Typescript type definitions, which should document most of the API.
@@ -176,6 +173,9 @@ For more usage examples check the [examples folder](./examples).
176173

177174
See [COMMON_ISSUES.md](./COMMON_ISSUES.md)
178175

176+
## Benchmarks
177+
Go [here](./benchmark)
178+
179179
## Supported Libcurl Versions
180180

181181
The addon is only tested against libcurl version `7.50.0` and the latest one available.
@@ -286,12 +286,12 @@ where `--target` is the current version of NW.js you are using
286286

287287
> yarn
288288
```bash
289-
npm_config_runtime=electron npm_config_target=$(yarn --silent electron --version) npm_config_disturl=https://atom.io/download/atom-shell yarn add node-libcurl
289+
npm_config_runtime=electron npm_config_target=$(yarn --silent electron --version) npm_config_disturl=https://www.electronjs.org/headers yarn add node-libcurl
290290
```
291291

292292
> npm
293293
```bash
294-
npm install node-libcurl --runtime=electron --target=$(yarn --silent electron --version) --disturl=https://atom.io/download/atom-shell --save
294+
npm install node-libcurl --runtime=electron --target=$(yarn --silent electron --version) --disturl=https://www.electronjs.org/headers --save
295295
```
296296

297297
Where `--target` is the version of electron you are using, in our case, we are just using the version returned by the locally installed `electron` binary.

0 commit comments

Comments
 (0)