공부/Node.js

axios response cookie 설정

딸기버블티 2023. 2. 2. 16:53

https://www.npmjs.com/package/cookie

 

cookie

HTTP server cookie parsing and serialization. Latest version: 0.5.0, last published: 10 months ago. Start using cookie in your project by running `npm i cookie`. There are 3494 other projects in the npm registry using cookie.

www.npmjs.com

쿠키 사용하기 위해

$ npm install cookie

명령어 이용해서 설치.

 

 

 

쿠키 사용 위해 react 코드 맨 위에 

var cookie = require('cookie');

선언해주기.

 

 

 

 

 

 

 

 

 

 

 

 

 

1
2
3
4
5
6
7
8
9
10
11
const getLogin = (req, res) => {
  axios
    .post("url"null, {
      params: { name1: "value1", name2: "value2", name3: "name3", ....},
    })
    .then((response) => {
      res.cookie('SESSION', response.data.sessionId, {domain : 'localhost', path:'/', httpOnly : true, session : true});
      res.cookie('abcd', response.data.sessionId, {domain : 'localhost', path:'/', httpOnly : true, session : true});
    
    });
};
 
cs

res => 응답

res.cookie 로 쿠키 세팅.

 

 

 

 

 

 

 

 

▲ 쿠키 생김

 

 

 

 

 

 

 

 

 

 

 

https://chrome.google.com/webstore/detail/cookie-editor/hlkenndednhfkekhgcdicdfddnkalmdm

 

Cookie-Editor

Simple yet powerful Cookie Editor that allow you to quickly create, edit and delete cookies without leaving your tab.

chrome.google.com

chrome  에서 쿠키 보려면 쿠키에디터 설치하면 된다.