Skip to content

Commit

Permalink
Added env variable checks for slack and appInsights (#295)
Browse files Browse the repository at this point in the history
  • Loading branch information
mlhaufe authored Jul 30, 2024
1 parent 0af55fe commit a77d5e0
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 7 deletions.
10 changes: 5 additions & 5 deletions .env.example
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ GH_CLIENT_ID: Ov23lij8q5YhcosEjIzQ
GH_CLIENT_SECRET: 27c98b69344086c13bc15290e1a8b8c86a910d58
AUTH_SECRET: e792b76a-2573-45d4-a39b-3b8db5712f9c
AUTH_ORIGIN: https://localhost:3000
SLACK_ADMIN_MEMBER_ID: ***
SLACK_BOT_TOKEN: ***
SLACK_SIGNING_SECRET: ***
APPINSIGHTS_CONNECTIONSTRING: ***
APPINSIGHTS_INSTRUMENTATIONKEY: ***
# SLACK_ADMIN_MEMBER_ID: ***
# SLACK_BOT_TOKEN: ***
# SLACK_SIGNING_SECRET: ***
# APPINSIGHTS_CONNECTIONSTRING: ***
# APPINSIGHTS_INSTRUMENTATIONKEY: ***
5 changes: 4 additions & 1 deletion plugins/appInsights.server.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
import appInsights from 'applicationinsights';

export default defineNuxtPlugin(nuxtApp => {
export default defineNuxtPlugin(async nuxtApp => {
if (!process.env.APPINSIGHTS_CONNECTIONSTRING)
return;

// https://learn.microsoft.com/en-us/azure/azure-monitor/app/nodejs#telemetryclient-api
appInsights.setup(process.env.APPINSIGHTS_CONNECTIONSTRING)
.setAutoCollectRequests(true)
Expand Down
8 changes: 7 additions & 1 deletion server/api/slack-bot/index.post.ts
Original file line number Diff line number Diff line change
Expand Up @@ -87,14 +87,20 @@ export default defineEventHandler(async (event) => {
rawBody = (await readRawBody(event))!,
headers = event.headers

if (!process.env.SLACK_BOT_TOKEN)
throw createError({
statusCode: 500,
statusMessage: 'Internal Server Error',
message: 'Slack bot token not found'
})

if (!body.success)
throw createError({
statusCode: 400,
statusMessage: 'Bad Request: Invalid body parameters',
message: JSON.stringify(body.error.errors)
})


ai.trackTrace({
message: `SlackBotMessage Headers: ${JSON.stringify(headers)}`
})
Expand Down

0 comments on commit a77d5e0

Please sign in to comment.