我正在编写一个应用程序,通过刮取外部域来构建API。为了刮去域名,我的服务器必须被授权(使用会话cookie)。确定cookie何时会与节点请求模块过期
我正在使用request module和cookie jar来维护跨请求的cookie。
我想设置一些节点路由器中间件,这样,如果/当会话过期时,我可以重新运行我的身份验证方法。想是这样的:
export function validate(req, res, next) {
const cookie = cookieJar.getCookie('**target domain**');
const COOKIE_IS_EXPIRED = // ???
if (COOKIE_IS_EXPIRED) {
authenticate().then(next);
} else {
next();
}
}
当我退出的cookieJar.getCookies()
内容我的结果是一样的东西如下:
[ Cookie="lw_opac_1=1483019929431275955; Expires=Wed, 29 Mar 2017 13:58:49 GMT; Max-Age=7776000; Path=/opac; hostOnly=true; aAge=0ms; cAge=6345ms",
Cookie="lw_opac=ta4tscsejs6c94ngikt7hlbcn0; Path=/; hostOnly=true; aAge=0ms; cAge=6347ms" ]
我如何可以验证时,这两个饼干接近/已过期,然后重新运行我的身份验证功能?
谢谢!
Did [my post](https://stackoverflow.com/questions/41380997/determine-when-cookie-will-expire-with-node-request-module/41381820#41381820)回答你的问题? – rsp