express - redirection

Minhyeok Kim·2022년 8월 30일
0

개념

목록 보기
3/13

express 를 사용해서 restful 한 프로그램을 작성할 때 보면, 경로를 재설정 해주는 경우가 많이 발생하게 된다. 이때 간편한 조작으로 경로를 재설정해주는 방법이 있다.

// 리 다이렉션
request.on('end', function(){
  var post = qs.parse(body);
  var little =post.title;
  var description = post.description;
  fs.writeFile(`data/${title}`, description, 'utf8', function(err){
    response.writeHead(302, {location: `/?id=${title}`})
    response.end();
  })
})

0개의 댓글