Add cert with force ssl
enable slack notifications tidy up rollbar a bit
This commit is contained in:
@@ -35,6 +35,7 @@
|
||||
"react-icons": "^2.2.3",
|
||||
"rollbar": "^0.6.3",
|
||||
"sequelize": "^3.28.0",
|
||||
"slack-node": "^0.1.8",
|
||||
"source-map-support": "^0.4.6",
|
||||
"sqlite3": "^3.1.8",
|
||||
"universal-router": "^2.0.0",
|
||||
|
||||
19
src/core/rollbar.js
Normal file
19
src/core/rollbar.js
Normal file
@@ -0,0 +1,19 @@
|
||||
import Rollbar from 'rollbar';
|
||||
import { analytics } from '../config';
|
||||
|
||||
const serverToken = analytics.rollbar.serverToken;
|
||||
|
||||
export default {
|
||||
errorHandler() {
|
||||
return Rollbar.errorHandler(serverToken);
|
||||
},
|
||||
handleError(err) {
|
||||
return Rollbar.handleError(err);
|
||||
},
|
||||
init() {
|
||||
Rollbar.init(serverToken);
|
||||
Rollbar.handleUncaughtExceptionsAndRejections(serverToken, {
|
||||
exitOnUncaughtException: true,
|
||||
});
|
||||
},
|
||||
};
|
||||
31
src/core/slack.js
Normal file
31
src/core/slack.js
Normal file
@@ -0,0 +1,31 @@
|
||||
import Slack from 'slack-node';
|
||||
import { slackWebhook } from '../config';
|
||||
import { handleError } from '../core/rollbar';
|
||||
|
||||
const slack = new Slack();
|
||||
slack.setWebhook(slackWebhook);
|
||||
|
||||
// Debounce sending the slack message to avoid spamming
|
||||
const slackTimers = {};
|
||||
|
||||
export const sendSlackMsg = function sendSlackMsg(text) {
|
||||
slack.webhook({
|
||||
channel: '#wedding-rsvps',
|
||||
username: 'weddingbot',
|
||||
text,
|
||||
}, err => {
|
||||
if (err) {
|
||||
handleError(err);
|
||||
}
|
||||
});
|
||||
};
|
||||
|
||||
export const sendSlackMsgWithDebounce = function sendSlackMsgWithDebounce(text, key) {
|
||||
if (key) {
|
||||
// Stop previous msg
|
||||
clearTimeout(slackTimers[key]);
|
||||
slackTimers[key] = setTimeout(() => {
|
||||
sendSlackMsg(text);
|
||||
}, 10000);
|
||||
}
|
||||
};
|
||||
@@ -10,7 +10,6 @@ import React from 'react';
|
||||
import ReactDOM from 'react-dom/server';
|
||||
import UniversalRouter from 'universal-router';
|
||||
import PrettyError from 'pretty-error';
|
||||
import Rollbar from 'rollbar';
|
||||
import App from './components/App';
|
||||
import Html from './components/Html';
|
||||
import { ErrorPageWithoutStyle } from './routes/error/ErrorPage';
|
||||
@@ -21,12 +20,15 @@ import models from './data/models';
|
||||
import schema from './data/schema';
|
||||
import routes from './routes';
|
||||
import assets from './assets'; // eslint-disable-line import/no-unresolved
|
||||
import { port, auth, analytics } from './config';
|
||||
import { port, auth, starters, mains } from './config';
|
||||
import Person from './data/models/Person';
|
||||
import Rollbar from './core/rollbar';
|
||||
import { sendSlackMsgWithDebounce } from './core/slack';
|
||||
|
||||
const app = express();
|
||||
|
||||
//
|
||||
Rollbar.init();
|
||||
|
||||
// Tell any CSS tooling (such as Material UI) to use all vendor prefixes if the
|
||||
// user agent is not known.
|
||||
// -----------------------------------------------------------------------------
|
||||
@@ -114,6 +116,12 @@ app.post('/rsvp/save', (req, res) => {
|
||||
key: req.body.key,
|
||||
},
|
||||
}).then(() => {
|
||||
Person.findOne({
|
||||
where: { key: req.body.key },
|
||||
}).then(data => {
|
||||
if (data.completed) {
|
||||
sendSlackMsgWithDebounce(`${data.firstname} ${data.lastname} has saved their RSVP:\n${data.firstname} ${data.attending ? 'is' : 'is not'} coming.${data.attending ? `\nStarter: ${starters[data.starter]}\nMain: ${mains[data.main]}\nDietary requirements: ${data.dietary ? data.dietary : 'None'}` : ''}`, req.body.key);
|
||||
}
|
||||
res.json({
|
||||
success: true,
|
||||
prop: req.body.prop,
|
||||
@@ -125,6 +133,13 @@ app.post('/rsvp/save', (req, res) => {
|
||||
err,
|
||||
});
|
||||
});
|
||||
}).catch(err => {
|
||||
Rollbar.handleError(err);
|
||||
res.json({
|
||||
success: false,
|
||||
err,
|
||||
});
|
||||
});
|
||||
} catch (err) {
|
||||
Rollbar.handleError(err);
|
||||
res.json({
|
||||
@@ -259,11 +274,7 @@ app.get('*', async (req, res, next) => {
|
||||
//
|
||||
// Error handling
|
||||
// -----------------------------------------------------------------------------
|
||||
Rollbar.init(analytics.rollbar.serverToken);
|
||||
Rollbar.handleUncaughtExceptionsAndRejections(analytics.rollbar.serverToken, {
|
||||
exitOnUncaughtException: true,
|
||||
});
|
||||
app.use(Rollbar.errorHandler(analytics.rollbar.serverToken));
|
||||
app.use(Rollbar.errorHandler());
|
||||
const pe = new PrettyError();
|
||||
pe.skipNodeFiles();
|
||||
pe.skipPackage('express');
|
||||
|
||||
23
yarn.lock
23
yarn.lock
@@ -4042,11 +4042,11 @@ lodash@^3.10.1:
|
||||
version "3.10.1"
|
||||
resolved "https://registry.yarnpkg.com/lodash/-/lodash-3.10.1.tgz#5bf45e8e49ba4189e17d482789dfd15bd140b7b6"
|
||||
|
||||
lodash@^4.0.0, lodash@^4.16.4, lodash@^4.17.2, lodash@^4.3.0, lodash@^4.6.1:
|
||||
lodash@^4.0.0, lodash@^4.16.4, lodash@^4.17.2, lodash@^4.6.1:
|
||||
version "4.17.2"
|
||||
resolved "https://registry.yarnpkg.com/lodash/-/lodash-4.17.2.tgz#34a3055babe04ce42467b607d700072c7ff6bf42"
|
||||
|
||||
lodash@^4.1.0, lodash@^4.17.4:
|
||||
lodash@^4.1.0, lodash@^4.15.0, lodash@^4.17.4, lodash@^4.3.0:
|
||||
version "4.17.4"
|
||||
resolved "https://registry.yarnpkg.com/lodash/-/lodash-4.17.4.tgz#78203a4d1c328ae1d86dca6460e369b57f4055ae"
|
||||
|
||||
@@ -5679,7 +5679,7 @@ repeating@^2.0.0:
|
||||
dependencies:
|
||||
is-finite "^1.0.0"
|
||||
|
||||
request@2, request@^2.61.0, request@^2.79.0:
|
||||
request@2, request@^2.61.0, request@^2.74.0, request@^2.79.0:
|
||||
version "2.79.0"
|
||||
resolved "https://registry.yarnpkg.com/request/-/request-2.79.0.tgz#4dfe5bf6be8b8cdc37fcf93e04b65577722710de"
|
||||
dependencies:
|
||||
@@ -5729,6 +5729,15 @@ request@2.78.0:
|
||||
tough-cookie "~2.3.0"
|
||||
tunnel-agent "~0.4.1"
|
||||
|
||||
requestretry@^1.2.2:
|
||||
version "1.12.0"
|
||||
resolved "https://registry.yarnpkg.com/requestretry/-/requestretry-1.12.0.tgz#7f10a2cd0edb7e43bf9a8b6cbfeda202fb320860"
|
||||
dependencies:
|
||||
extend "^3.0.0"
|
||||
lodash "^4.15.0"
|
||||
request "^2.74.0"
|
||||
when "^3.7.7"
|
||||
|
||||
require-directory@^2.1.1:
|
||||
version "2.1.1"
|
||||
resolved "https://registry.yarnpkg.com/require-directory/-/require-directory-2.1.1.tgz#8c64ad5fd30dab1c976e2344ffe7f792a6a6df42"
|
||||
@@ -6001,6 +6010,12 @@ sinon@^2.0.0-pre.3:
|
||||
samsam "^1.1.3"
|
||||
text-encoding "0.5.2"
|
||||
|
||||
slack-node@^0.1.8:
|
||||
version "0.1.8"
|
||||
resolved "https://registry.yarnpkg.com/slack-node/-/slack-node-0.1.8.tgz#cda98de8681485b301dc6742ddc3897117fad349"
|
||||
dependencies:
|
||||
requestretry "^1.2.2"
|
||||
|
||||
slash@^1.0.0:
|
||||
version "1.0.0"
|
||||
resolved "https://registry.yarnpkg.com/slash/-/slash-1.0.0.tgz#c41f2f6c39fc16d1cd17ad4b5d896114ae470d55"
|
||||
@@ -6808,7 +6823,7 @@ whatwg-fetch@>=0.10.0, whatwg-fetch@^2.0.1:
|
||||
version "2.0.1"
|
||||
resolved "https://registry.yarnpkg.com/whatwg-fetch/-/whatwg-fetch-2.0.1.tgz#078b9461bbe91cea73cbce8bb122a05f9e92b772"
|
||||
|
||||
when@^3.0.1, when@^3.1.0:
|
||||
when@^3.0.1, when@^3.1.0, when@^3.7.7:
|
||||
version "3.7.7"
|
||||
resolved "https://registry.yarnpkg.com/when/-/when-3.7.7.tgz#aba03fc3bb736d6c88b091d013d8a8e590d84718"
|
||||
|
||||
|
||||
Reference in New Issue
Block a user