You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Feature: Allow multiple Subject Alternative Name (SAN) extensions (#52)
* Feature: Adding multiple domains using subject alternative name (SAN)
* Update README with Docker and SAN instructions
* Update readme
* Readme polish
* Tweaks
* Formatting fixes
* Adjust pathForDomain
* Create a stable hash for directory path of SAN listed domains
* Merge SAN with validation features
* Tweak for latest typescript
Copy file name to clipboardExpand all lines: README.md
+92Lines changed: 92 additions & 0 deletions
Original file line number
Diff line number
Diff line change
@@ -97,6 +97,98 @@ The `certutil` tooling is installed in OS-specific ways:
97
97
so devcert will simply fallback to the wizard approach for Firefox outlined
98
98
above)
99
99
100
+
## Multiple domains (SAN)
101
+
If you are developing a multi-tenant app or have many apps locally, you can generate a security
102
+
certificate using `devcert` to also use the [Subject Alternative Name](https://en.wikipedia.org/wiki/Subject_Alternative_Name)
103
+
extension, just pass an array of domains instead.
104
+
105
+
```js
106
+
let ssl =awaitdevcert.certificateFor([
107
+
'localhost',
108
+
'local.api.example.com',
109
+
'local.example.com',
110
+
'local.auth.example.com'
111
+
]);
112
+
https.createServer(ssl, app).listen(3000);
113
+
```
114
+
115
+
## Docker and local development
116
+
If you are developing with Docker, one option is to install `devcert` into a base folder in your home directory and
117
+
generate certificates for all of your local Docker projects. See comments and caveats in [this issue](https://github.com/davewasmer/devcert/issues/17).
118
+
119
+
While not elegant, you only really need to do this as often as you add new domains locally, which is probably not very often.
120
+
121
+
The general script would look something like:
122
+
123
+
```js
124
+
// example: make a directory in home directory such as ~/devcert-util
125
+
// ~/devcert-util/generate.js
126
+
constfs=require('fs');
127
+
constdevcert=require('devcert');
128
+
129
+
// or if its just one domain - devcert.certificateFor('local.example.com')
130
+
devcert.certificateFor([
131
+
'localhost',
132
+
'local.api.example.com',
133
+
'local.example.com',
134
+
'local.auth.example.com'
135
+
])
136
+
.then(({key, cert}) => {
137
+
fs.writeFileSync('./certs/tls.key', key);
138
+
fs.writeFileSync('./certs/tls.cert', cert);
139
+
})
140
+
.catch(console.error);
141
+
```
142
+
143
+
An easy way to use the files generated from above script is to copy the `~/devcert-util/certs` folder into your Docker projects:
144
+
```
145
+
# local-docker-project-root/
146
+
🗀 certs/
147
+
🗎 tls.key
148
+
🗎 tls.cert
149
+
```
150
+
151
+
And add this line to your `.gitignore`:
152
+
```
153
+
certs/
154
+
```
155
+
156
+
These two files can now easily be used by any project, be it Node.js or something else.
157
+
158
+
In Node, within Docker, simply load the copied certificate files into your https server:
159
+
```js
160
+
constfs=require('fs');
161
+
constExpress=require('express');
162
+
constapp=newExpress();
163
+
https
164
+
.createServer({
165
+
key:fs.readFileSync('./certs/tls.key'),
166
+
cert:fs.readFileSync('./certs/tls.cert')
167
+
}, app)
168
+
.listen(3000);
169
+
```
170
+
171
+
Also works with webpack dev server or similar technologies:
172
+
```js
173
+
// webpack.config.js
174
+
constfs=require('fs');
175
+
176
+
module.exports= {
177
+
//...
178
+
devServer: {
179
+
contentBase:join(__dirname, 'dist'),
180
+
host:'0.0.0.0',
181
+
public:'local.api.example.com',
182
+
port:3000,
183
+
publicPath:'/',
184
+
https: {
185
+
key:fs.readFileSync('./certs/tls.key'),
186
+
cert:fs.readFileSync('./certs/tls.cert')
187
+
}
188
+
}
189
+
};
190
+
```
191
+
100
192
## How it works
101
193
102
194
When you ask for a development certificate, devcert will first check to see
0 commit comments