简体   繁体   English

Discord Oauth2 用于 GitHub 页面?

[英]Discord Oauth2 for GitHub Pages?

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')

How do I use Discord Oauth2 for GitHub Pages?如何将 Discord Oauth2 用于 GitHub 页面? It says that require is not defined.它说 require 没有定义。 And even on local hosting, it says that I had to wrap the strings in array in require('express') .甚至在本地主机上,它说我必须将字符串包装在require('express')中的数组中。 Then, it says that app.get is not a function.然后,它说app.get不是 function。

And after all of this, how do I make a request to retrieve the servers of the person logged in?在这一切之后,我如何请求检索登录者的服务器?

GitHub Pages is a statically hosted hosting service, whilst Express is a server-side framework server. 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. 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.

Source 资源

This means that you cannot use Express with GitHub Pages.这意味着您不能将 Express 与 GitHub 页面一起使用。 However, there are workarounds and alternatives.但是,有解决方法和替代方法。

Workaround: Load content client-side解决方法:加载内容客户端

This is the recommended route if you want to stick to GitHub Pages.如果您想坚持使用 GitHub 页面,这是推荐的路线。 You would have a static skeleton page given to the user and fill in the fields using JavaScript on the client.您将有一个 static 框架页面提供给用户,并在客户端上使用 JavaScript 填写字段。

There are multiple approaches to this method, however, it depends on how you are handling authentication.此方法有多种方法,但是,这取决于您如何处理身份验证。

Alternative: Use other hosting services替代方案:使用其他托管服务

I assume that you are using GitHub Pages because it is a free hosting service, but the catch is that it's static only.我假设您使用的是 GitHub 页面,因为它是免费的托管服务,但问题是它仅是 static。

Both Vercel and Netlify have something called serverless functions . VercelNetlify都有一些称为无服务器功能的东西。 With serverless functions, a new computing instance is spun up every time a person makes a request to your website.使用无服务器功能,每次有人向您的网站发出请求时,都会启动一个新的计算实例。 Here are some official guides on how to implement Express:以下是有关如何实施 Express 的一些官方指南:

Good luck with your project!祝你的项目好运!

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM