File tree Expand file tree Collapse file tree 3 files changed +26
-0
lines changed Expand file tree Collapse file tree 3 files changed +26
-0
lines changed Original file line number Diff line number Diff line change @@ -35,6 +35,8 @@ BOT_ID=id-of-your-bot
35
35
CLIENT_SECRET=your-client-secret
36
36
DISCORD_REDIRECT_URL=your-client-oauth2-redirect-url-with-identyfy-guilds.join
37
37
DISCORD_SERVER_INVITE=your-discord-server-invite
38
+ DISCORD_WEBHOOK_URL=discord-webhook-used-in-fullstack-open-course
39
+ DISCORD_WEBHOOK_TOKEN=token-for-the-discord-webhook
38
40
PORT=your-custom-backend-port
39
41
SESSION_SECRET=server-session-secret
40
42
BACKEND_SERVER_URL=backend-server-url-without-port
Original file line number Diff line number Diff line change @@ -6,6 +6,7 @@ const discordAuthRoute = require("./routes/discordAuth");
6
6
const discordJoinRoute = require ( "./routes/join" ) ;
7
7
const facultyAuthRoute = require ( "./routes/authenticateFaculty" ) ;
8
8
const metricsRoute = require ( "./routes/metrics" ) ;
9
+ const webhookProxyRoute = require ( "./routes/webhookProxy" ) ;
9
10
const defaultRouteHandler = require ( "./routes/defaultRouteHandler" ) ;
10
11
const defaultRouteErrorHandler = require ( "./routes/defaultRouteErrorHandler" ) ;
11
12
const flash = require ( "connect-flash" ) ;
@@ -38,6 +39,7 @@ module.exports = (sequelize) => {
38
39
app . use ( flash ( ) ) ;
39
40
app . use ( "/discordAuth" , discordAuthRoute ) ;
40
41
app . use ( "/join" , discordJoinRoute ) ;
42
+ app . use ( "/webhooks" , webhookProxyRoute ) ;
41
43
app . use ( "/authenticate_faculty" , facultyAuthRoute ) ;
42
44
app . use ( "/metrics" , metricsRoute ) ;
43
45
Original file line number Diff line number Diff line change
1
+ require ( "dotenv" ) . config ( )
2
+ const axios = require ( "axios" )
3
+ const router = require ( "express" ) . Router ( )
4
+
5
+ router . get ( "/:webhookId" , async ( req , res ) => {
6
+ // only allow POST
7
+ if ( req . method === "POST" ) {
8
+ const webhookUrl = `${ process . env . DISCORD_WEBHOOK_URL } /${ req . params . webhookId } /${ process . env . DISCORD_WEBHOOK_TOKEN } `
9
+ const webhookData = req . body
10
+ try {
11
+ await axios . post ( webhookUrl , webhookData )
12
+ res . status ( 200 ) . send ( "Webhook sent successfully" )
13
+ } catch ( error ) {
14
+ console . error ( error )
15
+ res . status ( 500 ) . send ( "Internal server error" )
16
+ }
17
+ } else {
18
+ res . status ( 405 ) . send ( "Method not allowed" )
19
+ }
20
+ } )
21
+
22
+ module . exports = router
You can’t perform that action at this time.
0 commit comments