From 50f4c9a1b83d157563010e2e383f72bf1c931984 Mon Sep 17 00:00:00 2001 From: Shay Date: Thu, 5 May 2022 15:25:34 -0700 Subject: [PATCH] Add replit support --- README.md | 4 +++- app.js | 6 ++++-- package.json | 3 ++- 3 files changed, 9 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index 6387645..4de1409 100644 --- a/README.md +++ b/README.md @@ -4,7 +4,7 @@ This project contains a basic rock-paper-scissors-style Discord app written in J ![Demo of app](/assets/getting-started-demo.gif?raw=true) -> ✨ A version of this code is also hosted **[on Glitch 🎏](https://glitch.com/edit/#!/getting-started-discord)**. +> ✨ A version of this code is also hosted **[on Glitch 🎏](https://glitch.com/~getting-started-discord)** and **[on Replit 🌀](https://replit.com/@shaydewael/discord-example-app)** ## Project structure Below is a basic overview of the project structure: @@ -50,6 +50,8 @@ Fetch the credentials from your app's settings and add them to a `.env` file (se Fetching credentials is covered in detail in the [getting started guide](https://discord.com/developers/docs/getting-started). +> 🔑 Environment variables can be added to the `.env` file in Glitch or when developing locally, and in the Secrets tab in Replit (the lock icon on the left). + ### Run the app After your credentials are added, go ahead and run the app: diff --git a/app.js b/app.js index 707d4a7..3b52716 100644 --- a/app.js +++ b/app.js @@ -17,6 +17,8 @@ import { // Create an express app const app = express(); +// Get port, or default to 3000 +const PORT = process.env.PORT || 3000; // Parse request body and verifies incoming requests using discord-interactions package app.use(express.json({ verify: VerifyDiscordRequest(process.env.PUBLIC_KEY) })); @@ -173,8 +175,8 @@ app.post('/interactions', async function (req, res) { } }); -app.listen(3000, () => { - console.log('Listening on port 3000'); +app.listen(PORT, () => { + console.log('Listening on port', PORT); // Check if guild commands from commands.json are installed (if not, install them) HasGuildCommands(process.env.APP_ID, process.env.GUILD_ID, [ diff --git a/package.json b/package.json index a0b858c..e0f1986 100644 --- a/package.json +++ b/package.json @@ -5,7 +5,8 @@ "main": "app.js", "type": "module", "scripts": { - "start": "node app.js" + "start": "node app.js", + "dev": "nodemon app.js" }, "author": "Shay DeWael", "license": "MIT",