我正在編寫一個應用程序,通過刮取外部域來構建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