hiring-assessment 미완성 문제풀이

코드깎는 노인·2019년 8월 29일
0

hiring-assessment

목록 보기
1/1

Hiring Assesment 미완성문제

//Fill in vars here
const url = require("url");
const http = require("http");


const fs = require("file-system");

const server = http
  .createServer(function(request, response) {
    var path = url.parse(request.url, true).pathname;

    if (request.method === "POST") {
      if ((path = "hifive")) {
        response.writeHead(200, { "content-length": "7154" });
        response.end();
      }
      if((path='lowfive'))
    } else if (request.method === "GET") {
      if (path === "/") {
        response.writeHead(200, { "Content-Type": "text/html" });
        fs.readFile(__dirname + "/index.html", function(err, data) {
          if (err) console.log(err);
          response.end(data);
        });
      }
    } else {
      response.end(404);
    }
  })
  .listen(4568, "127.0.0.1");

console.log("Listening...");

module.exports = server;
---------------------------------------------------------------------------------------
if (request.method === 'POST') {
    if (path === '/hifive') {
      fs.readFile(__dirname + '/assets/hifive.jpg', function (err, data) {
        if (err) console.log(err);
        response.writeHead(200, { 'Content-Type': 'image/jpeg', 'content-length': data.length });
        response.end(data);
      });
    }

    else if (path === '/lowfive') {
      fs.readFile(__dirname + '/assets/lowfive.jpg', function (err, data) {
        if (err) console.log(err);
        response.writeHead(200, { 'Content-Type': 'image/jpeg', 'content-length': data.length });
        response.end(data);
      });
    }

    else {
      response.end(404);
    }

  } else if (request.method === 'GET') {
    if (path === '/') {
      response.writeHead(200, { 'Content-Type': 'text/html' });
      fs.readFile(__dirname + '/index.html', function (err, data) {
        if (err) console.log(err);
        response.end(data);
      });
    }
  } else {
    response.end(404);
  }

내가 문제를 이해한바는 서버요청을 통해 writefile로 로컬에 index.html파일을 바꾸는 기능을 구현하는줄 알았다.

하지만 단지 저장된 사진파일의 데이터길이만 보내주면 되는 단순한 문제였다.writefile로 로컬파일을 수정하는

기능에 대해서는 좀더 공부해봐야겠다

profile
내가 볼려고 만든 블로그

0개의 댓글