![](/img/trans.png)
[英]Node.JS and Express res.redirect() not enabling new webpage
[英]How can I add query parameters to a node.js/express.js res.redirect function?
我正在嘗試使用重定向用戶到我的應用程序中的 Google 授權頁面。 對於我的情況,我不能使用任何 Google API 模塊。
我知道我可以這樣格式化我的res.redirect()
函數:
res.redirect('https://accounts.google.com/o/oauth2/auth?scope=https%3A%2F%2Fwww.googleapis.com%2Fauth%2Fcalendar.readonly&response_type=code&redirect_uri=https%3A%2F%2Flocalhost%3A3000%2Fauth&client_id=690512789525-g8dbv0s1jo80u5hvevptqapeqokq7ees.apps.googleusercontent.com&hl=en&from_login=1&as=-6cc9a02870d13e22&authuser=0')
但我更喜歡更簡潔的東西,我可以將查詢參數保存在一個對象中。 就像是:
res.redirect({
uri: 'https://accounts.google.com/o/oauth2/auth,
scope: 'https://............etc',
response_type: 'code',
[...etc...]
})
將我的每個查詢參數作為對象中的屬性值對。
關於如何做到這一點的任何想法?
認為你需要這樣的東西url.format(urlObj)
: https : url.format(urlObj)
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.