Browse Source

initial commit

Rich Brown 1 year ago
commit
c6e73e9e37
8 changed files with 6612 additions and 0 deletions
  1. 8
    0
      .eslintrc.js
  2. 73
    0
      .gitignore
  3. 173
    0
      build/main.js
  4. 1
    0
      build/main.map
  5. 6282
    0
      package-lock.json
  6. 29
    0
      package.json
  7. 30
    0
      routes/blog-router.js
  8. 16
    0
      src/index.js

+ 8
- 0
.eslintrc.js View File

@@ -0,0 +1,8 @@
1
+module.exports = {
2
+    "extends": "airbnb",
3
+    "plugins": [
4
+        "react",
5
+        "jsx-a11y",
6
+        "import"
7
+    ]
8
+};

+ 73
- 0
.gitignore View File

@@ -0,0 +1,73 @@
1
+# Logs
2
+logs
3
+*.log
4
+npm-debug.log*
5
+yarn-debug.log*
6
+yarn-error.log*
7
+
8
+# Runtime data
9
+pids
10
+*.pid
11
+*.seed
12
+*.pid.lock
13
+
14
+# Directory for instrumented libs generated by jscoverage/JSCover
15
+lib-cov
16
+
17
+# Coverage directory used by tools like istanbul
18
+coverage
19
+
20
+# nyc test coverage
21
+.nyc_output
22
+
23
+# Grunt intermediate storage (https://gruntjs.com/creating-plugins#storing-task-files)
24
+.grunt
25
+
26
+# Bower dependency directory (https://bower.io/)
27
+bower_components
28
+
29
+# node-waf configuration
30
+.lock-wscript
31
+
32
+# Compiled binary addons (https://nodejs.org/api/addons.html)
33
+build/Release
34
+
35
+# Dependency directories
36
+node_modules/
37
+jspm_packages/
38
+
39
+# TypeScript v1 declaration files
40
+typings/
41
+
42
+# Optional npm cache directory
43
+.npm
44
+
45
+# Optional eslint cache
46
+.eslintcache
47
+
48
+# Optional REPL history
49
+.node_repl_history
50
+
51
+# Output of 'npm pack'
52
+*.tgz
53
+
54
+# Yarn Integrity file
55
+.yarn-integrity
56
+
57
+# dotenv environment variables file
58
+.env
59
+
60
+# parcel-bundler cache (https://parceljs.org/)
61
+.cache
62
+
63
+# next.js build output
64
+.next
65
+
66
+# nuxt.js build output
67
+.nuxt
68
+
69
+# vuepress build output
70
+.vuepress/dist
71
+
72
+# Serverless directories
73
+.serverless

+ 173
- 0
build/main.js View File

@@ -0,0 +1,173 @@
1
+require('source-map-support/register')
2
+module.exports =
3
+/******/ (function(modules) { // webpackBootstrap
4
+/******/ 	// The module cache
5
+/******/ 	var installedModules = {};
6
+/******/
7
+/******/ 	// The require function
8
+/******/ 	function __webpack_require__(moduleId) {
9
+/******/
10
+/******/ 		// Check if module is in cache
11
+/******/ 		if(installedModules[moduleId]) {
12
+/******/ 			return installedModules[moduleId].exports;
13
+/******/ 		}
14
+/******/ 		// Create a new module (and put it into the cache)
15
+/******/ 		var module = installedModules[moduleId] = {
16
+/******/ 			i: moduleId,
17
+/******/ 			l: false,
18
+/******/ 			exports: {}
19
+/******/ 		};
20
+/******/
21
+/******/ 		// Execute the module function
22
+/******/ 		modules[moduleId].call(module.exports, module, module.exports, __webpack_require__);
23
+/******/
24
+/******/ 		// Flag the module as loaded
25
+/******/ 		module.l = true;
26
+/******/
27
+/******/ 		// Return the exports of the module
28
+/******/ 		return module.exports;
29
+/******/ 	}
30
+/******/
31
+/******/
32
+/******/ 	// expose the modules object (__webpack_modules__)
33
+/******/ 	__webpack_require__.m = modules;
34
+/******/
35
+/******/ 	// expose the module cache
36
+/******/ 	__webpack_require__.c = installedModules;
37
+/******/
38
+/******/ 	// define getter function for harmony exports
39
+/******/ 	__webpack_require__.d = function(exports, name, getter) {
40
+/******/ 		if(!__webpack_require__.o(exports, name)) {
41
+/******/ 			Object.defineProperty(exports, name, {
42
+/******/ 				configurable: false,
43
+/******/ 				enumerable: true,
44
+/******/ 				get: getter
45
+/******/ 			});
46
+/******/ 		}
47
+/******/ 	};
48
+/******/
49
+/******/ 	// getDefaultExport function for compatibility with non-harmony modules
50
+/******/ 	__webpack_require__.n = function(module) {
51
+/******/ 		var getter = module && module.__esModule ?
52
+/******/ 			function getDefault() { return module['default']; } :
53
+/******/ 			function getModuleExports() { return module; };
54
+/******/ 		__webpack_require__.d(getter, 'a', getter);
55
+/******/ 		return getter;
56
+/******/ 	};
57
+/******/
58
+/******/ 	// Object.prototype.hasOwnProperty.call
59
+/******/ 	__webpack_require__.o = function(object, property) { return Object.prototype.hasOwnProperty.call(object, property); };
60
+/******/
61
+/******/ 	// __webpack_public_path__
62
+/******/ 	__webpack_require__.p = "/";
63
+/******/
64
+/******/ 	// Load entry module and return exports
65
+/******/ 	return __webpack_require__(__webpack_require__.s = 1);
66
+/******/ })
67
+/************************************************************************/
68
+/******/ ([
69
+/* 0 */
70
+/***/ (function(module, exports) {
71
+
72
+module.exports = require("express");
73
+
74
+/***/ }),
75
+/* 1 */
76
+/***/ (function(module, exports, __webpack_require__) {
77
+
78
+module.exports = __webpack_require__(2);
79
+
80
+
81
+/***/ }),
82
+/* 2 */
83
+/***/ (function(module, __webpack_exports__, __webpack_require__) {
84
+
85
+"use strict";
86
+Object.defineProperty(__webpack_exports__, "__esModule", { value: true });
87
+/* harmony import */ var __WEBPACK_IMPORTED_MODULE_0_express__ = __webpack_require__(0);
88
+/* harmony import */ var __WEBPACK_IMPORTED_MODULE_0_express___default = __webpack_require__.n(__WEBPACK_IMPORTED_MODULE_0_express__);
89
+/* harmony import */ var __WEBPACK_IMPORTED_MODULE_1_cors__ = __webpack_require__(3);
90
+/* harmony import */ var __WEBPACK_IMPORTED_MODULE_1_cors___default = __webpack_require__.n(__WEBPACK_IMPORTED_MODULE_1_cors__);
91
+/* harmony import */ var __WEBPACK_IMPORTED_MODULE_2_compression__ = __webpack_require__(4);
92
+/* harmony import */ var __WEBPACK_IMPORTED_MODULE_2_compression___default = __webpack_require__.n(__WEBPACK_IMPORTED_MODULE_2_compression__);
93
+/* harmony import */ var __WEBPACK_IMPORTED_MODULE_3__routes_blog_router__ = __webpack_require__(5);
94
+
95
+
96
+
97
+
98
+
99
+
100
+const app = __WEBPACK_IMPORTED_MODULE_0_express___default()();
101
+
102
+app.use(__WEBPACK_IMPORTED_MODULE_2_compression___default()());
103
+app.use(__WEBPACK_IMPORTED_MODULE_1_cors___default()());
104
+app.use(__WEBPACK_IMPORTED_MODULE_0_express___default.a.urlencoded({ extended: false }));
105
+app.use(__WEBPACK_IMPORTED_MODULE_0_express___default.a.json());
106
+app.use('/blog', __WEBPACK_IMPORTED_MODULE_3__routes_blog_router__["a" /* blogRouter */]);
107
+app.get('*', (req, res) => res.senStatus(404));
108
+
109
+app.listen(8081, () => console.log('On 8081')); //eslint-disable-line
110
+
111
+/***/ }),
112
+/* 3 */
113
+/***/ (function(module, exports) {
114
+
115
+module.exports = require("cors");
116
+
117
+/***/ }),
118
+/* 4 */
119
+/***/ (function(module, exports) {
120
+
121
+module.exports = require("compression");
122
+
123
+/***/ }),
124
+/* 5 */
125
+/***/ (function(module, __webpack_exports__, __webpack_require__) {
126
+
127
+"use strict";
128
+/* harmony import */ var __WEBPACK_IMPORTED_MODULE_0_express__ = __webpack_require__(0);
129
+/* harmony import */ var __WEBPACK_IMPORTED_MODULE_0_express___default = __webpack_require__.n(__WEBPACK_IMPORTED_MODULE_0_express__);
130
+/* harmony import */ var __WEBPACK_IMPORTED_MODULE_1_axios__ = __webpack_require__(6);
131
+/* harmony import */ var __WEBPACK_IMPORTED_MODULE_1_axios___default = __webpack_require__.n(__WEBPACK_IMPORTED_MODULE_1_axios__);
132
+
133
+
134
+
135
+
136
+__webpack_require__(7).config();
137
+
138
+const blogRouter = __WEBPACK_IMPORTED_MODULE_0_express___default.a.Router();
139
+/* harmony export (immutable) */ __webpack_exports__["a"] = blogRouter;
140
+ //eslint-disable-line
141
+
142
+blogRouter.post('/notify', async (req, res) => {
143
+  const toSlack = {};
144
+  if (req.body.email) {
145
+    toSlack.email = req.body.email;
146
+  }
147
+
148
+  if (req.body.textarea) {
149
+    toSlack.textarea = req.body.textarea;
150
+  }
151
+
152
+  __WEBPACK_IMPORTED_MODULE_1_axios___default.a.post(process.env.WEBHOOK, {
153
+    text: `got a blog inquiry: ${JSON.stringify(toSlack)}`
154
+  }, {
155
+    headers: { 'Content-type': 'application/json' }
156
+  }).then(() => res.send({ message: `received ${req.body.email} and alerting admins` })).catch(e => console.log(e)); //eslint-disable-line
157
+});
158
+
159
+/***/ }),
160
+/* 6 */
161
+/***/ (function(module, exports) {
162
+
163
+module.exports = require("axios");
164
+
165
+/***/ }),
166
+/* 7 */
167
+/***/ (function(module, exports) {
168
+
169
+module.exports = require("dotenv");
170
+
171
+/***/ })
172
+/******/ ]);
173
+//# sourceMappingURL=main.map

+ 1
- 0
build/main.map
File diff suppressed because it is too large
View File


+ 6282
- 0
package-lock.json
File diff suppressed because it is too large
View File


+ 29
- 0
package.json View File

@@ -0,0 +1,29 @@
1
+{
2
+  "name": "@shoesandsocks/notifier",
3
+  "version": "1.0.0",
4
+  "description": "a personal slack notifier",
5
+  "main": "index.js",
6
+  "scripts": {
7
+    "test": "echo \"Error: no test specified\" && exit 1",
8
+    "dev": "backpack",
9
+    "build": "backpack build",
10
+    "start": "npm run build && node ./src/index.js"
11
+  },
12
+  "author": "",
13
+  "license": "ISC",
14
+  "dependencies": {
15
+    "axios": "^0.18.0",
16
+    "backpack-core": "^0.7.0",
17
+    "compression": "^1.7.3",
18
+    "cors": "^2.8.4",
19
+    "dotenv": "^6.0.0",
20
+    "express": "^4.16.3"
21
+  },
22
+  "devDependencies": {
23
+    "eslint": "^5.6.1",
24
+    "eslint-config-airbnb": "^17.1.0",
25
+    "eslint-plugin-import": "^2.14.0",
26
+    "eslint-plugin-jsx-a11y": "^6.1.1",
27
+    "eslint-plugin-react": "^7.11.1"
28
+  }
29
+}

+ 30
- 0
routes/blog-router.js View File

@@ -0,0 +1,30 @@
1
+
2
+import express from 'express';
3
+import axios from 'axios';
4
+
5
+require('dotenv').config();
6
+
7
+export const blogRouter = express.Router(); //eslint-disable-line
8
+
9
+blogRouter.post('/notify', async (req, res) => {
10
+  const toSlack = {};
11
+  if (req.body.email) {
12
+    toSlack.email = req.body.email;
13
+  }
14
+
15
+  if (req.body.textarea) {
16
+    toSlack.textarea = req.body.textarea;
17
+  }
18
+
19
+  axios.post(
20
+    process.env.WEBHOOK,
21
+    {
22
+      text: `got a blog inquiry: ${JSON.stringify(toSlack)}`,
23
+    },
24
+    {
25
+      headers: { 'Content-type': 'application/json' },
26
+    },
27
+  )
28
+    .then(() => res.send({ message: `received ${req.body.email} and alerting admins` }))
29
+    .catch(e => console.log(e)); //eslint-disable-line
30
+});

+ 16
- 0
src/index.js View File

@@ -0,0 +1,16 @@
1
+import express from 'express';
2
+import cors from 'cors';
3
+import compression from 'compression';
4
+
5
+import { blogRouter } from '../routes/blog-router';
6
+
7
+const app = express();
8
+
9
+app.use(compression());
10
+app.use(cors());
11
+app.use(express.urlencoded({ extended: false }));
12
+app.use(express.json());
13
+app.use('/blog', blogRouter);
14
+app.get('*', (req, res) => res.senStatus(404));
15
+
16
+app.listen(8081, () => console.log('On 8081')); //eslint-disable-line