update
This commit is contained in:
@ -693,48 +693,70 @@ export class SmartCertManager {
|
||||
path: '/.well-known/acme-challenge/*'
|
||||
},
|
||||
action: {
|
||||
type: 'static',
|
||||
handler: async (context) => {
|
||||
// Extract the token from the path
|
||||
const token = context.path?.split('/').pop();
|
||||
if (!token) {
|
||||
return { status: 404, body: 'Not found' };
|
||||
}
|
||||
|
||||
// Create mock request/response objects for SmartAcme
|
||||
const mockReq = {
|
||||
url: context.path,
|
||||
method: 'GET',
|
||||
headers: context.headers || {}
|
||||
};
|
||||
|
||||
let responseData: any = null;
|
||||
const mockRes = {
|
||||
statusCode: 200,
|
||||
setHeader: (name: string, value: string) => {},
|
||||
end: (data: any) => {
|
||||
responseData = data;
|
||||
type: 'socket-handler',
|
||||
socketHandler: (socket, context) => {
|
||||
// Wait for HTTP request data
|
||||
socket.once('data', async (data) => {
|
||||
const request = data.toString();
|
||||
const lines = request.split('\r\n');
|
||||
const [method, path] = lines[0].split(' ');
|
||||
|
||||
// Extract the token from the path
|
||||
const token = path?.split('/').pop();
|
||||
if (!token) {
|
||||
socket.write('HTTP/1.1 404 Not Found\r\n');
|
||||
socket.write('Content-Type: text/plain\r\n');
|
||||
socket.write('Content-Length: 9\r\n');
|
||||
socket.write('Connection: close\r\n');
|
||||
socket.write('\r\n');
|
||||
socket.write('Not found');
|
||||
socket.end();
|
||||
return;
|
||||
}
|
||||
};
|
||||
|
||||
// Use SmartAcme's handler
|
||||
const handled = await new Promise<boolean>((resolve) => {
|
||||
http01Handler.handleRequest(mockReq as any, mockRes as any, () => {
|
||||
resolve(false);
|
||||
});
|
||||
// Give it a moment to process
|
||||
setTimeout(() => resolve(true), 100);
|
||||
});
|
||||
|
||||
if (handled && responseData) {
|
||||
return {
|
||||
status: mockRes.statusCode,
|
||||
headers: { 'Content-Type': 'text/plain' },
|
||||
body: responseData
|
||||
|
||||
// Create mock request/response objects for SmartAcme
|
||||
const mockReq = {
|
||||
url: path,
|
||||
method: 'GET',
|
||||
headers: {}
|
||||
};
|
||||
} else {
|
||||
return { status: 404, body: 'Not found' };
|
||||
}
|
||||
|
||||
let responseData: any = null;
|
||||
const mockRes = {
|
||||
statusCode: 200,
|
||||
setHeader: (name: string, value: string) => {},
|
||||
end: (data: any) => {
|
||||
responseData = data;
|
||||
}
|
||||
};
|
||||
|
||||
// Use SmartAcme's handler
|
||||
const handled = await new Promise<boolean>((resolve) => {
|
||||
http01Handler.handleRequest(mockReq as any, mockRes as any, () => {
|
||||
resolve(false);
|
||||
});
|
||||
// Give it a moment to process
|
||||
setTimeout(() => resolve(true), 100);
|
||||
});
|
||||
|
||||
if (handled && responseData) {
|
||||
const body = String(responseData);
|
||||
socket.write(`HTTP/1.1 ${mockRes.statusCode} OK\r\n`);
|
||||
socket.write('Content-Type: text/plain\r\n');
|
||||
socket.write(`Content-Length: ${body.length}\r\n`);
|
||||
socket.write('Connection: close\r\n');
|
||||
socket.write('\r\n');
|
||||
socket.write(body);
|
||||
} else {
|
||||
socket.write('HTTP/1.1 404 Not Found\r\n');
|
||||
socket.write('Content-Type: text/plain\r\n');
|
||||
socket.write('Content-Length: 9\r\n');
|
||||
socket.write('Connection: close\r\n');
|
||||
socket.write('\r\n');
|
||||
socket.write('Not found');
|
||||
}
|
||||
socket.end();
|
||||
});
|
||||
}
|
||||
}
|
||||
};
|
||||
|
Reference in New Issue
Block a user