-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathssl.config.ts
More file actions
35 lines (31 loc) · 1.24 KB
/
ssl.config.ts
File metadata and controls
35 lines (31 loc) · 1.24 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
import { existsSync, readFileSync } from "node:fs";
import { join } from "node:path";
/**
* Returns `cert` and `key` of local certificates, if found.
*
* This is meant to be used for local development only.
* While on Azure, SSL is provided by the platform and this function just returns `null`.
* Astro will start in `http`-mode but Azure proxies the request to use `https`.
*/
export function getHttpsConfig(
args: { certPath: string; keyPath: string } = {
certPath: join(process.cwd(), ".certs/localhost.pem"),
keyPath: join(process.cwd(), ".certs/localhost-key.pem"),
},
): {
cert: Buffer;
key: Buffer;
} | null {
const { certPath, keyPath } = args;
if (existsSync(certPath) && existsSync(keyPath)) {
// Use mkcert certificates for trusted HTTPS
return { cert: readFileSync(certPath), key: readFileSync(keyPath) };
}
// Fallback to basic SSL plugin if mkcert certificates don't exist
console.warn(
"⚠️ Local certificates not found. Using basic SSL plugin.\n" +
" To enable trusted certificates for Cursor's browser, run:\n" +
` mkdir .certs && mkcert -key-file ${keyPath} -cert-file ${certPath} localhost 127.0.0.1 ::1`,
);
return null;
}