I’m stuck on Stage #AP6.
I’ve tried everything gpt asked friend but not able to get where i am wrong
Here are my logs:
remote: [tester::#AP6] >
remote: [tester::#AP6] Sent bytes: “GET /files/non-existentblueberry_blueberry_raspberry_raspberry HTTP/1.1\r\nHost: localhost:4221\r\n\r\n”
remote: [tester::#AP6] Failed to read response:
remote: [tester::#AP6] Received: “” (no content received)
remote: [tester::#AP6] ^ error
remote: [tester::#AP6] Error: Expected: HTTP-version, Received: “”
remote: [tester::#AP6] Test failed
remote: [tester::#AP6] Terminating program
remote: [tester::#AP6] Program terminated successfully
remote:
And here’s a snippet of my code:
else if (url.includes('/files/') && method === "GET") {
const directory = process.argv[3];
const filename = url.split("/files/")[1];
const filePath = `../${directory}/${filename}`;
if (fs.existsSync(filePath)) {
// Respond with the file content
const content = fs.readFileSync(filePath).toString();
const res = `HTTP/1.1 200 OK\r\nContent-Type: application/octet-stream\r\nContent-Length: ${Buffer.byteLength(content)}\r\n\r\n${content}`;
socket.write(res);
socket.end();
} else {
// Respond with 404 Not Found
const res = 'HTTP/1.1 404 Not Found\r\nContent-Length: 0\r\n\r\n';
socket.write(res);
}
socket.end();
}