var express = require('express')()
const app = express();
var port = {
'client_id': '…',
'client_secret': '…',
'grant_type': 'authorization_code',
'redirect_uri': '…',
}
app.get('/', (request, response) => {
return response.sendFile('index.html', { root: '.' });
});
app.listen(port, () => console.log(`App listening at http://localhost:${port}`));
console.log('1')
如何将 Discord Oauth2 用于 GitHub 页面?它说未定义要求。甚至在本地主机上,它说我必须将字符串包装在 require('express')
中的数组中。然后,它说 app.get
不是函数。
在所有这一切之后,我该如何发出请求来检索登录人的服务器?
最佳答案
GitHub Pages 是一个静态托管托管服务,而 Express 是一个服务器端框架服务器。
GitHub Pages is a static site hosting service that takes HTML, CSS, and JavaScript files straight from a repository on GitHub, optionally runs the files through a build process, and publishes a website.
这意味着您不能将 Express 与 GitHub Pages 一起使用。但是,有一些解决方法和替代方案。
解决方法:在客户端加载内容
如果您想坚持使用 GitHub Pages,这是推荐的路线。您将向用户提供一个静态框架页面,并在客户端使用 JavaScript 填写字段。
此方法有多种方法,但是,这取决于您处理身份验证的方式。
备选方案:使用其他托管服务
我假设您正在使用 GitHub Pages,因为它是一项免费的托管服务,但问题是它只是静态的。
两者都是Vercel和 Netlify有个东西叫serverless functions .使用无服务器功能,每当有人向您的网站发出请求时,都会启动一个新的计算实例。以下是有关如何实现 Express 的一些官方指南:
祝你的项目好运!
关于javascript - GitHub 页面的 Discord Oauth2?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/70400809/