简体   繁体   English

如何在快速打字稿中获取 cookie

[英]How to get cookie in express typescript

Thank you for coming here i've been configing server by express and typescript i did success to make cookie like this code感谢您来到这里我一直在通过 express 和 typescript 配置服务器我成功地制作了像这段代码这样的 cookie

app.get('/',req: Request, res: Response) => {
    // res.cookie('park', 'juhong');
    return res.send('cookie!');
}))

but when i try to get cookie by cookie-parser it doesn't work但是当我尝试通过 cookie-parser 获取 cookie 时它不起作用

const cookieParser = require('cookie-parser');
app.use(cookieParser);
app.get('/', (req: Request, res: Response) => {
 console.log(req.cookies);
 return res.send('cookie!');
})

How to get cookie in express typescript?如何在快速打字稿中获取 cookie?

set a cookie: res.cookie('name', value, { httpOnly: true, expires: expire })设置 cookie: res.cookie('name', value, { httpOnly: true, expires: expire })

get a cookie: req.cookies['cookie-name']获取 cookie: req.cookies['cookie-name']

then in client version for example if you make a request with axios you need to enable property withCredentials然后在客户端版本中,例如,如果您使用 axios 发出请求,则需要启用属性withCredentials

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM