Skip to content

Commit

Permalink
feat: add selfsignedAttrs option (#9)
Browse files Browse the repository at this point in the history
* feat: add selfsignedAttrs option

* fix
  • Loading branch information
chenjiahan authored Jul 17, 2024
1 parent 465f75a commit d218627
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 2 deletions.
19 changes: 19 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,25 @@ pluginBasicSsl({
});
```

### selfsignedAttrs

Attributes passing to `selfsigned`, see [selfsigned](https://github.com/jfromaniello/selfsigned) for details.

- **Type:** `CertificateField[]`
- **Default:**

```ts
const defaultAttrs = [{ name: "commonName", value: "localhost" }];
```

- **Example:**

```ts
pluginBasicSsl({
selfsignedAttrs: [{ name: "commonName", value: "example.com" }],
});
```

### selfsignedOptions

Options passing to `selfsigned`, see [selfsigned - Options](https://github.com/jfromaniello/selfsigned?tab=readme-ov-file#options) for details.
Expand Down
6 changes: 5 additions & 1 deletion src/index.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import type { RsbuildPlugin } from '@rsbuild/core';
import type { SelfsignedOptions } from 'selfsigned';
import type { SelfsignedOptions, generate } from 'selfsigned';
import { resolveHttpsConfig } from './util.js';

export const PLUGIN_BASIC_SSL_NAME = 'rsbuild:basic-ssl';
Expand All @@ -15,6 +15,10 @@ export type PluginBasicSslOptions = {
* @default __dirname
*/
outputPath?: string;
/**
* Attributes passing to `selfsigned`.
*/
selfsignedAttrs?: Parameters<typeof generate>[0];
/**
* Options passing to `selfsigned`.
*/
Expand Down
2 changes: 1 addition & 1 deletion src/util.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ export const resolveHttpsConfig = async (
}

const pem = selfsigned.generate(
[{ name: 'commonName', value: 'localhost' }],
options.selfsignedAttrs ?? [{ name: 'commonName', value: 'localhost' }],
selfsignedOptions,
);

Expand Down

0 comments on commit d218627

Please sign in to comment.