Skip to content

Commit 1ec4b3a

Browse files
committed
Better naming of middlewares
1 parent 6f172cd commit 1ec4b3a

File tree

6 files changed

+12
-10
lines changed

6 files changed

+12
-10
lines changed

README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,8 @@ An accompanying static web app also shows the registered commands: https://nextj
3232

3333
## Development
3434

35+
Requires a Node.js version that can run Next.js.
36+
3537
### Setup
3638

3739
Follow the one-time setup as follows:

interfaces/discord.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { APIApplicationCommandInteraction, APIInteractionResponse } from "discord-api-types"
1+
import { APIApplicationCommandInteraction, APIInteractionResponse } from "discord-api-types/v8"
22
import { NextApiRequest, NextApiResponse } from "next"
33

44
export type DiscordInteractionApiHandler = (
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ export const verifyHeaders = ({ timestamp, rawBody, signature }: VerifyHeadersAr
3434
*
3535
* When using this middleware, your API route handler must disable body parsing
3636
*/
37-
const discordInteraction = (next: DiscordInteractionApiHandler) => async (
37+
const withDiscordInteraction = (next: DiscordInteractionApiHandler) => async (
3838
req: NextApiRequest,
3939
res: NextApiResponse
4040
) => {
@@ -69,4 +69,4 @@ const discordInteraction = (next: DiscordInteractionApiHandler) => async (
6969
}
7070
}
7171

72-
export default discordInteraction
72+
export default withDiscordInteraction
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { NextApiHandler, NextApiRequest, NextApiResponse } from "next"
22

3-
const handleErrors = (fn: NextApiHandler) => async (req: NextApiRequest, res: NextApiResponse) => {
3+
const withErrorHandler = (fn: NextApiHandler) => async (req: NextApiRequest, res: NextApiResponse) => {
44
try {
55
return await fn(req, res)
66
} catch (err) {
@@ -10,4 +10,4 @@ const handleErrors = (fn: NextApiHandler) => async (req: NextApiRequest, res: Ne
1010
}
1111
}
1212

13-
export default handleErrors
13+
export default withErrorHandler

pages/api/interactions/index.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
import axios from "axios"
22
import { NextApiRequest, NextApiResponse } from "next"
33
import { customAlphabet } from "nanoid"
4-
import { APIApplicationCommandInteraction, APIEmbed, APIInteractionResponse } from "discord-api-types/payloads/v8"
5-
import discordInteraction from "middlewares/discord"
6-
import handleErrors from "middlewares/errors"
4+
import { APIApplicationCommandInteraction, APIEmbed, APIInteractionResponse } from "discord-api-types/v8"
5+
import withDiscordInteraction from "middlewares/discord-interaction"
6+
import withErrorHandler from "middlewares/error-handler"
77

88
const nanoid = customAlphabet("abcdefghijklmnopqrstuvwxyz-", 16)
99

@@ -88,4 +88,4 @@ const handler = async (
8888
}
8989
}
9090

91-
export default handleErrors(discordInteraction(handler))
91+
export default withErrorHandler(withDiscordInteraction(handler))

services/discord.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import axios from "axios"
2-
import { APIApplicationCommand } from "discord-api-types"
2+
import { APIApplicationCommand } from "discord-api-types/v8"
33

44
const DISCORD_APP_ID = process.env.DISCORD_APP_ID
55
const DISCORD_BOT_TOKEN = process.env.DISCORD_BOT_TOKEN

0 commit comments

Comments
 (0)