Add cert with force ssl

enable slack notifications
tidy up rollbar a bit
This commit is contained in:
2017-02-10 17:13:25 +00:00
parent 14e7aeeb5c
commit 97d5370e65
5 changed files with 93 additions and 16 deletions

View File

@@ -35,6 +35,7 @@
"react-icons": "^2.2.3", "react-icons": "^2.2.3",
"rollbar": "^0.6.3", "rollbar": "^0.6.3",
"sequelize": "^3.28.0", "sequelize": "^3.28.0",
"slack-node": "^0.1.8",
"source-map-support": "^0.4.6", "source-map-support": "^0.4.6",
"sqlite3": "^3.1.8", "sqlite3": "^3.1.8",
"universal-router": "^2.0.0", "universal-router": "^2.0.0",

19
src/core/rollbar.js Normal file
View 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
View 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);
}
};

View File

@@ -10,7 +10,6 @@ import React from 'react';
import ReactDOM from 'react-dom/server'; import ReactDOM from 'react-dom/server';
import UniversalRouter from 'universal-router'; import UniversalRouter from 'universal-router';
import PrettyError from 'pretty-error'; import PrettyError from 'pretty-error';
import Rollbar from 'rollbar';
import App from './components/App'; import App from './components/App';
import Html from './components/Html'; import Html from './components/Html';
import { ErrorPageWithoutStyle } from './routes/error/ErrorPage'; import { ErrorPageWithoutStyle } from './routes/error/ErrorPage';
@@ -21,12 +20,15 @@ import models from './data/models';
import schema from './data/schema'; import schema from './data/schema';
import routes from './routes'; import routes from './routes';
import assets from './assets'; // eslint-disable-line import/no-unresolved 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 Person from './data/models/Person';
import Rollbar from './core/rollbar';
import { sendSlackMsgWithDebounce } from './core/slack';
const app = express(); const app = express();
// Rollbar.init();
// Tell any CSS tooling (such as Material UI) to use all vendor prefixes if the // Tell any CSS tooling (such as Material UI) to use all vendor prefixes if the
// user agent is not known. // user agent is not known.
// ----------------------------------------------------------------------------- // -----------------------------------------------------------------------------
@@ -114,6 +116,12 @@ app.post('/rsvp/save', (req, res) => {
key: req.body.key, key: req.body.key,
}, },
}).then(() => { }).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({ res.json({
success: true, success: true,
prop: req.body.prop, prop: req.body.prop,
@@ -125,6 +133,13 @@ app.post('/rsvp/save', (req, res) => {
err, err,
}); });
}); });
}).catch(err => {
Rollbar.handleError(err);
res.json({
success: false,
err,
});
});
} catch (err) { } catch (err) {
Rollbar.handleError(err); Rollbar.handleError(err);
res.json({ res.json({
@@ -259,11 +274,7 @@ app.get('*', async (req, res, next) => {
// //
// Error handling // Error handling
// ----------------------------------------------------------------------------- // -----------------------------------------------------------------------------
Rollbar.init(analytics.rollbar.serverToken); app.use(Rollbar.errorHandler());
Rollbar.handleUncaughtExceptionsAndRejections(analytics.rollbar.serverToken, {
exitOnUncaughtException: true,
});
app.use(Rollbar.errorHandler(analytics.rollbar.serverToken));
const pe = new PrettyError(); const pe = new PrettyError();
pe.skipNodeFiles(); pe.skipNodeFiles();
pe.skipPackage('express'); pe.skipPackage('express');

View File

@@ -4042,11 +4042,11 @@ lodash@^3.10.1:
version "3.10.1" version "3.10.1"
resolved "https://registry.yarnpkg.com/lodash/-/lodash-3.10.1.tgz#5bf45e8e49ba4189e17d482789dfd15bd140b7b6" 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" version "4.17.2"
resolved "https://registry.yarnpkg.com/lodash/-/lodash-4.17.2.tgz#34a3055babe04ce42467b607d700072c7ff6bf42" 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" version "4.17.4"
resolved "https://registry.yarnpkg.com/lodash/-/lodash-4.17.4.tgz#78203a4d1c328ae1d86dca6460e369b57f4055ae" resolved "https://registry.yarnpkg.com/lodash/-/lodash-4.17.4.tgz#78203a4d1c328ae1d86dca6460e369b57f4055ae"
@@ -5679,7 +5679,7 @@ repeating@^2.0.0:
dependencies: dependencies:
is-finite "^1.0.0" 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" version "2.79.0"
resolved "https://registry.yarnpkg.com/request/-/request-2.79.0.tgz#4dfe5bf6be8b8cdc37fcf93e04b65577722710de" resolved "https://registry.yarnpkg.com/request/-/request-2.79.0.tgz#4dfe5bf6be8b8cdc37fcf93e04b65577722710de"
dependencies: dependencies:
@@ -5729,6 +5729,15 @@ request@2.78.0:
tough-cookie "~2.3.0" tough-cookie "~2.3.0"
tunnel-agent "~0.4.1" 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: require-directory@^2.1.1:
version "2.1.1" version "2.1.1"
resolved "https://registry.yarnpkg.com/require-directory/-/require-directory-2.1.1.tgz#8c64ad5fd30dab1c976e2344ffe7f792a6a6df42" 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" samsam "^1.1.3"
text-encoding "0.5.2" 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: slash@^1.0.0:
version "1.0.0" version "1.0.0"
resolved "https://registry.yarnpkg.com/slash/-/slash-1.0.0.tgz#c41f2f6c39fc16d1cd17ad4b5d896114ae470d55" 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" version "2.0.1"
resolved "https://registry.yarnpkg.com/whatwg-fetch/-/whatwg-fetch-2.0.1.tgz#078b9461bbe91cea73cbce8bb122a05f9e92b772" 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" version "3.7.7"
resolved "https://registry.yarnpkg.com/when/-/when-3.7.7.tgz#aba03fc3bb736d6c88b091d013d8a8e590d84718" resolved "https://registry.yarnpkg.com/when/-/when-3.7.7.tgz#aba03fc3bb736d6c88b091d013d8a8e590d84718"