Reputation: 87
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? It says that require is not defined. And even on local hosting, it says that I had to wrap the strings in array in require('express')
. Then, it says that app.get
is not a function.
And after all of this, how do I make a request to retrieve the servers of the person logged in?
Upvotes: 3
Views: 414
Reputation: 335
GitHub Pages is a statically hosted hosting service, whilst Express is a server-side framework server.
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.
This means that you cannot use Express with GitHub Pages. However, there are workarounds and alternatives.
This is the recommended route if you want to stick to GitHub Pages. You would have a static skeleton page given to the user and fill in the fields using JavaScript on the client.
There are multiple approaches to this method, however, it depends on how you are handling authentication.
I assume that you are using GitHub Pages because it is a free hosting service, but the catch is that it's static only.
Both Vercel and Netlify have something called serverless functions. 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:
Good luck with your project!
Upvotes: 3