javascript - 如何将查询参数添加到 node.js/express.js res.redirect 函数?

标签 javascript node.js express

我正在尝试将用户重定向到我的应用中的 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://nodejs.org/docs/latest/api/url.html#url_url_format_urlobj

关于javascript - 如何将查询参数添加到 node.js/express.js res.redirect 函数?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30823857/

相关文章:

页面上的javascript随机图像加载并在一段时间内发生变化

javascript - 如何选择由 jQuery 生成的元素?

javascript - Web 开发人员如何查看用户控制台错误?

javascript - Node.js 上的客户端 : Uncaught ReferenceError: require is not defined

node.js - 快速 CSRF token 验证

javascript - 当前时间和开始时间(source 标签中的 startat 属性)匹配时,如何播放视频?

javascript - 尝试在iOS webview应用程序中使用speechSynthesis API

javascript - Angular js : an arrray from one file to another

node.js - JWT认证时如何区分用户类型

node.js - 使用 "npx create-react-app my-app,"创建我的 React 应用程序后,npm start 向我抛出 ELIFECYCLE 错误。做什么?