Skip to content

Commit

Permalink
return a file
Browse files Browse the repository at this point in the history
  • Loading branch information
kripa-sindhu-007 committed Jun 26, 2024
1 parent 6c7dcde commit e66ee9e
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions app/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,9 @@ const server = net.createServer((socket) => {
const temp = `HTTP/1.1 200 OK\r\nContent-Type: text/plain\r\nContent-Length: ${actualLength}\r\n\r\n`;
socket.write(temp + content);
} else if (url.startsWith("/files/")) {
const dir = process.argv[3];
const directory = process.argv[3];
const filename = url.split("/files/")[1];
if (fs.existsSync("${directory}/${filename}")) {
if (fs.existsSync(`${directory}/${filename}`)) {
const content = fs.readFileSync("${directory}/${filename}").toString();
const res = `HTTP/1.1 200 OK\r\nContent-Type: application/octet-stream\r\nContent-Length: ${content.length}\r\n\r\n${content}\r\n`;
socket.write(res);
Expand Down

0 comments on commit e66ee9e

Please sign in to comment.