Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: allow to specify ssl: true in connection options #3387

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions lib/base/connection.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,11 @@ class BaseConnection extends EventEmitter {
constructor(opts) {
super();
this.config = opts.config;

if (typeof this.config.ssl === 'boolean' ) {
this.config.ssl = this.config.ssl === true ? {} : undefined;
}

// TODO: fill defaults
// if no params, connect to /var/lib/mysql/mysql.sock ( /tmp/mysql.sock on OSX )
// if host is given, connect to host:3306
Expand Down
2 changes: 1 addition & 1 deletion typings/mysql/lib/Connection.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -268,7 +268,7 @@ export interface ConnectionOptions {
/**
* object with ssl parameters or a string containing name of ssl profile
*/
ssl?: string | SslOptions;
ssl?: string | boolean | SslOptions;

/**
* Return each row as an array, not as an object.
Expand Down
4 changes: 2 additions & 2 deletions website/docs/documentation/ssl.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,12 @@ See full list of [SslOptions](https://github.com/sidorares/node-mysql2/blob/mast

## SSL Options

To enable SSL without manually providing certificates and assuming they are already trusted by the host machine, you can specify an empty object, for example:
To enable SSL without manually providing certificates and assuming they are already trusted by the host machine, you can specify `ssl: true` or `ssl: {}`, for example:

```ts
const connection = await mysql.createConnection({
host: 'localhost',
ssl: {},
ssl: true,
});
```

Expand Down
2 changes: 1 addition & 1 deletion website/docs/examples/connections/create-connection.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,7 @@ const mysql = require('mysql2');

const connection = mysql.createConnection({
// ...
ssl: {},
ssl: true,
});

connection.addListener('error', (err) => {
Expand Down
Loading