Skip to content

Commit

Permalink
#147 postでdev環境に通知する関数の作成
Browse files Browse the repository at this point in the history
  • Loading branch information
RikitoNoto committed Aug 23, 2023
1 parent 4ad4ce9 commit 05a4a67
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 4 deletions.
26 changes: 26 additions & 0 deletions functions/src/callable-functions/notificationSlack.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
import axios from 'axios';
import { https } from 'firebase-functions/v2';

export const notificationSlack = https.onRequest(async (request, response) => {
if (request.method === `OPTIONS`) {
response.set(`Access-Control-Allow-Methods`, `POST`);
response.set(`Access-Control-Allow-Headers`, `Content-Type`);
response.status(204).send(``);
}
else if (request.method === `POST`) {
if (request.body[`text`]) {
const endpoint = process.env.SLACK_ENDPOINT
if (!endpoint) {
response.status(400).send(`could not find SLACK_ENDPOINT`);
return;
}
axios.post(endpoint, { text: request.body[`text`] });
response.status(200).send(`OK`);
}
else {
response.status(400).send(`invalid parameter. You must include 'text' param in the body`);
}
} else {
response.status(405).send(`invalid method`);
}
});
9 changes: 5 additions & 4 deletions functions/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,9 @@ admin.initializeApp({
/** Firebase Functions のグローバル設定。 */
functions.setGlobalOptions({ region: `asia-northeast1` })

// /** ここでデプロイする関数をまとめる。 */
// import { createfirebaseauthcustomtoken } from './createFirebaseAuthCustomToken'
/** ここでデプロイする関数をまとめる。 */
import { createfirebaseauthcustomtoken } from './callable-functions/createFirebaseAuthCustomToken'
import { notificationSlack } from './callable-functions/notificationSlack'

// /** index.ts で import してデプロイする関数一覧。 */
// export { createfirebaseauthcustomtoken }
/** index.ts で import してデプロイする関数一覧。 */
export { createfirebaseauthcustomtoken, notificationSlack }

0 comments on commit 05a4a67

Please sign in to comment.