diff --git a/app.js b/app.js index d13f55c..7f2a5c5 100644 --- a/app.js +++ b/app.js @@ -93,7 +93,7 @@ async function start() { try { await app.ready(); app.swagger(); - await app.listen({ port: 3000, host: 'localhost' }); + await app.listen({ port: 3000, host: '0.0.0.0' }); app.log.info('Server listening on http://localhost:3000'); } catch (err) { app.log.error(err); diff --git a/discord.js b/discord.js index d31f796..18797e6 100644 --- a/discord.js +++ b/discord.js @@ -3,9 +3,12 @@ const db = require('./db'); const BOT_ID = "1410578978712060024"; const BOT_SECRET = "vhk6jp_jYjvShOqpI8MJ2Efjjm_9Cmyi"; -const REDIRECT_URI = "http://localhost:3000/auth/discord/callback"; exports.handleDiscordAuth = async (request, reply) => { + const protocol = request.protocol || (request.headers['x-forwarded-proto'] || '').split(',')[0] || 'http'; + const host = request.hostname || request.headers.host; + const REDIRECT_URI = `${protocol}://${host}/auth/discord/callback`; + const code = request.query.code; if (!code) return reply.code(400).send({ error: "Code de validation manquant" }); try { diff --git a/routes/other.js b/routes/other.js index f13eb97..d8037f3 100644 --- a/routes/other.js +++ b/routes/other.js @@ -10,8 +10,11 @@ module.exports = async function (app, opts) { // --- Auth Discord --- app.get('/auth/discord', async (req, reply) => { + const protocol = req.protocol || (req.headers['x-forwarded-proto'] || '').split(',')[0] || 'http'; + const host = req.hostname || req.headers.host; + const redirectUri = `${protocol}://${host}/auth/discord/callback`; + const clientId = '1410578978712060024'; - const redirectUri = 'http://localhost:3000/auth/discord/callback'; const scope = 'identify email'; const discordAuthUrl = `https://discord.com/api/oauth2/authorize?client_id=${clientId}&redirect_uri=${encodeURIComponent(redirectUri)}&response_type=code&scope=${scope}`; reply.redirect(discordAuthUrl);