const fs = require('fs'); const path = require('path'); const selfsigned = require('selfsigned'); const outDir = path.resolve(__dirname, '..', 'certs'); fs.mkdirSync(outDir, { recursive: true }); const attrs = [{ name: 'commonName', value: 'localhost' }]; const opts = { days: 365, keySize: 2048, extensions: [{ name: 'subjectAltName', altNames: [{ type: 2, value: 'localhost' }, { type: 7, ip: '127.0.0.1' }] }] }; const pems = selfsigned.generate(attrs, opts); const keyPath = path.join(outDir, 'localhost.key'); const certPath = path.join(outDir, 'localhost.crt'); fs.writeFileSync(keyPath, pems.private, { mode: 0o600 }); fs.writeFileSync(certPath, pems.cert, { mode: 0o644 }); console.log('Wrote key:', keyPath); console.log('Wrote cert:', certPath); console.log('To start HTTPS server using these certs run:'); console.log(' SSL_KEY_PATH=' + keyPath + ' SSL_CERT_PATH=' + certPath + ' npm start');