-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpfx-server.ts
More file actions
56 lines (45 loc) · 1.37 KB
/
pfx-server.ts
File metadata and controls
56 lines (45 loc) · 1.37 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
import { serve } from 'bun';
import fs from 'fs';
import path from 'path';
// Store temporary PFX files in memory
const pfxStorage = new Map<string, Buffer>();
// Create server to host PFX files
const server = serve({
port: 8080,
fetch(req) {
const url = new URL(req.url);
// Serve PFX files
if (url.pathname.startsWith('/pfx/')) {
const fileId = url.pathname.replace('/pfx/', '');
const pfxBuffer = pfxStorage.get(fileId);
if (pfxBuffer) {
return new Response(pfxBuffer, {
headers: {
'Content-Type': 'application/x-pkcs12',
'Access-Control-Allow-Origin': '*'
}
});
}
return new Response('PFX not found', { status: 404 });
}
// Health check
if (url.pathname === '/') {
return new Response(`PFX Server Running\nActive files: ${pfxStorage.size}`, {
headers: { 'Content-Type': 'text/plain' }
});
}
return new Response('Not found', { status: 404 });
}
});
console.log(`🚀 PFX Server running at http://localhost:${server.port}`);
// Export functions to manage PFX storage
export function storePFX(id: string, buffer: Buffer): string {
pfxStorage.set(id, buffer);
return `http://localhost:${server.port}/pfx/${id}`;
}
export function removePFX(id: string) {
pfxStorage.delete(id);
}
export function clearAllPFX() {
pfxStorage.clear();
}