Skip to content
Merged
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
8 changes: 3 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -87,14 +87,12 @@ pluginBasicSsl({

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

In addition, the plugin supports a `days` option to set the validity period of the certificate. It is converted to `notAfterDate` and ignored if `notAfterDate` is set.

- **Type:** `SelfsignedOptions & { days?: number }`
- **Type:** `SelfsignedOptions`
- **Default:**

```ts
const defaultOptions = {
days: 30,
notAfterDate: new Date(Date.now() + 30 * 24 * 60 * 60 * 1000),
keySize: 2048,
};
```
Expand All @@ -104,7 +102,7 @@ const defaultOptions = {
```ts
pluginBasicSsl({
selfsignedOptions: {
days: 100,
notAfterDate: new Date(Date.now() + 100 * 24 * 60 * 60 * 1000),
},
});
```
Expand Down
9 changes: 1 addition & 8 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,14 +22,7 @@ export type PluginBasicSslOptions = {
/**
* Options passing to `selfsigned`.
*/
selfsignedOptions?: SelfsignedOptions & {
/**
* Validity period of the certificate in days.
* Ignored if `notAfterDate` is set.
* @default 30
*/
days?: number;
};
selfsignedOptions?: SelfsignedOptions;
};

export const pluginBasicSsl = (
Expand Down
5 changes: 2 additions & 3 deletions src/util.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,11 +46,10 @@ export const resolveHttpsConfig = async (
options.filename ?? 'fake-cert.pem',
);

const { days = 30, ...restOptions } = options.selfsignedOptions ?? {};
const selfsignedOptions = {
keySize: 2048,
notAfterDate: new Date(Date.now() + days * 24 * 60 * 60 * 1000),
...restOptions,
notAfterDate: new Date(Date.now() + 30 * 24 * 60 * 60 * 1000),
...options.selfsignedOptions,
};

if (fs.existsSync(certPath)) {
Expand Down
2 changes: 1 addition & 1 deletion test/selfsigned-options/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ test('should print HTTPS server URLs when custom selfsigned options', async () =
plugins: [
pluginBasicSsl({
selfsignedOptions: {
days: 1,
notAfterDate: new Date(Date.now() + 24 * 60 * 60 * 1000),
},
}),
],
Expand Down
Loading