study / okdevtv star
허광남 허광남 03-01
notify
@45b2089a2913cef377a8699f824703842f7ef5f5
.env.sample
--- .env.sample
+++ .env.sample
@@ -8,6 +8,7 @@
 GITHUB_CLIENT_ID=b
 GITHUB_CLIENT_SECRET=f
 SLACK_HOOK_URL=slack
+WEBHOOK_DISCORD=discord
 SENTRY_URL=sentry
 
 BASE_URL=http://localhost:3000
 
config_/config.js (deleted)
--- config_/config.js
@@ -1,16 +0,0 @@
-require('dotenv').config()
-module.exports = {
-  /*
-   * This file contains the configurations information of Twitter login app.
-   * It consists of Twitter app information, database information.
-   */
-
-  facebook_api_key: process.env.FACEBOOK_API_KEY,
-  facebook_api_secret: process.env.FACEBOOK_API_SECRET,
-  callback_url: `${process.env.BASE_URL}/auth/facebook/callback`,
-  use_database: false,
-  host: 'localhost',
-  username: process.env.DB_USER,
-  password: process.env.DB_PASS,
-  database: process.env.DB_NAME,
-}
 
lib/notify.js (added)
+++ lib/notify.js
@@ -0,0 +1,23 @@
+const axios = require('axios')
+require('dotenv').config()
+
+function notify(message) {
+  axios({
+    method: 'post',
+    url: process.env.WEBHOOK_DISCORD,
+    headers: {
+      'Content-Type': 'application/json',
+    },
+    data: JSON.stringify({
+      content: '=====\n' + message,
+    }),
+  })
+    .then((response) => {
+      console.log(response.status, response.headers.date)
+    })
+    .catch((error) => {
+      console.error(error)
+    })
+}
+
+module.exports = notify
lib/user.js
--- lib/user.js
+++ lib/user.js
@@ -1,4 +1,5 @@
 const { sequelize, Model, DataTypes } = require('../lib/db')
+const notify = require('../lib/notify')
 
 class User extends Model {}
 User.init(
@@ -13,6 +14,7 @@
 async function create(data) {
   await sequelize.sync()
   const row = await User.create(data)
+  notify(row.dataValues.email + ' 님이 가입했습니다.')
   return row
 }
 
Add a comment
List