Skip to content

Commit d218627

Browse files
authored
feat: add selfsignedAttrs option (#9)
* feat: add selfsignedAttrs option * fix
1 parent 465f75a commit d218627

3 files changed

Lines changed: 25 additions & 2 deletions

File tree

README.md

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,25 @@ pluginBasicSsl({
6666
});
6767
```
6868

69+
### selfsignedAttrs
70+
71+
Attributes passing to `selfsigned`, see [selfsigned](https://github.com/jfromaniello/selfsigned) for details.
72+
73+
- **Type:** `CertificateField[]`
74+
- **Default:**
75+
76+
```ts
77+
const defaultAttrs = [{ name: "commonName", value: "localhost" }];
78+
```
79+
80+
- **Example:**
81+
82+
```ts
83+
pluginBasicSsl({
84+
selfsignedAttrs: [{ name: "commonName", value: "example.com" }],
85+
});
86+
```
87+
6988
### selfsignedOptions
7089

7190
Options passing to `selfsigned`, see [selfsigned - Options](https://github.com/jfromaniello/selfsigned?tab=readme-ov-file#options) for details.

src/index.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import type { RsbuildPlugin } from '@rsbuild/core';
2-
import type { SelfsignedOptions } from 'selfsigned';
2+
import type { SelfsignedOptions, generate } from 'selfsigned';
33
import { resolveHttpsConfig } from './util.js';
44

55
export const PLUGIN_BASIC_SSL_NAME = 'rsbuild:basic-ssl';
@@ -15,6 +15,10 @@ export type PluginBasicSslOptions = {
1515
* @default __dirname
1616
*/
1717
outputPath?: string;
18+
/**
19+
* Attributes passing to `selfsigned`.
20+
*/
21+
selfsignedAttrs?: Parameters<typeof generate>[0];
1822
/**
1923
* Options passing to `selfsigned`.
2024
*/

src/util.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ export const resolveHttpsConfig = async (
5757
}
5858

5959
const pem = selfsigned.generate(
60-
[{ name: 'commonName', value: 'localhost' }],
60+
options.selfsignedAttrs ?? [{ name: 'commonName', value: 'localhost' }],
6161
selfsignedOptions,
6262
);
6363

0 commit comments

Comments
 (0)