-
Notifications
You must be signed in to change notification settings - Fork 12
Expand file tree
/
Copy pathdev-https.js
More file actions
57 lines (47 loc) · 1.61 KB
/
dev-https.js
File metadata and controls
57 lines (47 loc) · 1.61 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
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
import { createServer as createHttpsServer } from 'https';
import { createServer as createViteServer } from 'vite';
import fs from 'fs';
import path from 'path';
// Generate a self-signed certificate for development
const generateCert = () => {
// For development purposes, we'll use a basic self-signed cert
// In a real scenario, you'd use mkcert or similar tools
const cert = `-----BEGIN CERTIFICATE-----
MIIDXTCCAkWgAwIBAgIJAKLdQwjTRIQXMA0GCSqGSIb3DQEBCwUAMEUxCzAJBgNV
BAYTAlVTMRMwEQYDVQQIDApTb21lLVN0YXRlMSEwHwYDVQQKDBhJbnRlcm5ldCBX
aWRnaXRzIFB0eSBMdGQwHhcNMjMwMTAxMDAwMDAwWhcNMjQwMTAxMDAwMDAwWjBF
...
-----END CERTIFICATE-----`;
const key = `-----BEGIN PRIVATE KEY-----
MIIEvwIBADANBgkqhkiG9w0BAQEFAASCBKkwggSlAgEAAoIBAQDZ0+1Zr9znRqF
...
-----END PRIVATE KEY-----`;
return { cert, key };
};
async function startDevServer() {
try {
const vite = await createViteServer({
server: { middlewareMode: true },
appType: 'spa'
});
const { cert, key } = generateCert();
const httpsServer = createHttpsServer({ cert, key }, vite.middlewares);
httpsServer.listen(5173, () => {
console.log('🚀 HTTPS Dev Server running at https://localhost:5173');
console.log('⚡ PWA-ready development environment');
});
} catch (error) {
console.error('Error starting HTTPS dev server:', error);
}
}
startDevServer();
// Handle graceful shutdown
const shutdown = () => {
console.log('\nShutting down HTTPS dev server...');
httpsServer.close(() => {
console.log('Server closed');
process.exit(0);
});
};
process.on('SIGINT', shutdown);
process.on('SIGTERM', shutdown);