This app requires more setup to run locally than a traditional web app due to Discord applications needing a public endpoint. For local testing, we must create a new application with Discord and create an HTTP tunnel between our local dev server and a public endpoint. The only prerequisite is having pnpm installed.
-
Create a discord application for development on the Discord Developer Dashboard (you can call it
shorter-devor something similar):- After creating your app, copy your Public Key and Application ID and save them somewhere safe.
- Go to the Bot tab and copy your token, again saving it somewhere safe.
-
cdinto the bot package directory. -
Run
openssl rand -hex 32to generate yourSHORTER_API_KEY. -
Create a local
.dev.varsfile by runningcp .dev.vars.example .dev.varsand paste your newly obtained credentials into it. -
Run
pnpm inviteand add the bot to a server you'd like to test it in. -
Run
pnpm registerto register the app's commands with Discord. -
Start a local dev server and create an HTTP tunnel:
- Run
pnpm devto start a local dev server onlocalhost:8787. - Run
pnpm tunnelin a different terminal, it should display a public URL that forwards the dev server you started in the previous step. - Visit the URL in your browser. If you did everything correctly, you should see the message
Hi!.
- Run
-
Paste your public URL into the Interactions Endpoint URL field back on the Discord Developer Dashboard.
cdinto the service package directory.- Create a local
.dev.varsfile by runningcp .dev.vars.example .dev.varsand paste yourSHORTER_API_KEYinto it. - Run
pnpm devin a third terminal to start a local dev server onlocalhost:8788.
Make sure you run pnpm check in both packages before submitting. You can run pnpm check:write to apply any fixes the tool finds.