Skip to content
This repository was archived by the owner on Jun 28, 2021. It is now read-only.

Commit c233869

Browse files
committed
Adding sentry (#327)
1 parent 8a6918a commit c233869

File tree

10 files changed

+41
-11
lines changed

10 files changed

+41
-11
lines changed

.env

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,3 +2,5 @@ NODE_ENV=development
22
PORT=8000
33
API_URL=http://quran.com:3000
44
SEGMENTS_KEY=
5+
SENTRY_KEY_CLIENT=
6+
SENTRY_KEY_SERVER=

Dockerfile

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@ FROM node:5.10.0
22

33
ENV NODE_ENV production
44
ENV API_URL http://api.quran.com:3000
5+
ENV SENTRY_KEY_CLIENT https://[email protected]/80639
6+
ENV SENTRY_KEY_SERVER https://44c105328ae544ae9928f9eb74b40061:[email protected]/80639
57
ENV PORT 8000
68

79
RUN apt-get -y update && apt-get -y install supervisor ssh rsync

client.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ import { syncHistoryWithStore } from 'react-router-redux';
1515

1616
import debug from 'debug';
1717

18+
import config from 'config';
1819
import ApiClient from './src/helpers/ApiClient';
1920
import createStore from './src/redux/create';
2021
import routes from './src/routes';
@@ -23,6 +24,8 @@ const client = new ApiClient();
2324
const store = createStore(browserHistory, client, window.__data);
2425
const history = syncHistoryWithStore(browserHistory, store);
2526

27+
Raven.config(config.sentryClient).install()
28+
2629
window.quranDebug = debug;
2730
window.ReactDOM = ReactDOM; // For chrome dev tool support
2831

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,7 @@
7575
"promise": "^7.0.4",
7676
"proxy-middleware": "^0.14.0",
7777
"qs": "^6.1.0",
78+
"raven": "^0.11.0",
7879
"raw-loader": "^0.5.1",
7980
"react": "^0.14.8",
8081
"react-bootstrap": "^0.28.4",

server.js

Lines changed: 23 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,15 @@ import { ReduxAsyncConnect, loadOnServer } from 'redux-connect';
77
import createHistory from 'react-router/lib/createMemoryHistory';
88
import { Provider } from 'react-redux';
99
import cookie from 'react-cookie';
10+
import raven from 'raven';
11+
import errorhandler from 'errorhandler';
1012

11-
13+
import config from 'config';
1214
import expressConfig from 'server/config/express';
1315

1416
const pretty = new PrettyError();
1517
const server = express();
18+
1619
expressConfig(server);
1720

1821
import routes from './src/routes';
@@ -26,6 +29,7 @@ import { setUserAgent } from './src/redux/modules/audioplayer';
2629
import { setOption } from './src/redux/modules/options';
2730

2831
// Use varnish for the static routes, which will cache too
32+
server.use(raven.middleware.express.requestHandler(config.sentryServer));
2933

3034
server.use((req, res, next) => {
3135
cookie.plugToRequest(req, res);
@@ -59,28 +63,40 @@ server.use((req, res, next) => {
5963
res.status(500).send(error);
6064
} else if (renderProps) {
6165
loadOnServer({...renderProps, store, helpers: { client }}).then(() => {
62-
const component = ReactDOM.renderToString(
66+
const component = (
6367
<Provider store={store}>
6468
<ReduxAsyncConnect {...renderProps} />
6569
</Provider>
6670
);
6771

68-
debug('Server', 'Rendering Application component into html');
69-
debug('Server', 'Sending markup');
7072
res.type('html');
7173
res.setHeader('Cache-Control', 'public, max-age=31557600');
72-
res.status(200).send('<!doctype html>\n' + ReactDOM.renderToString(
74+
res.status(200);
75+
debug('Server', 'Sending markup');
76+
res.send('<!doctype html>\n' + ReactDOM.renderToString(
7377
<Html
7478
component={component}
7579
store={store}
7680
assets={webpack_isomorphic_tools.assets()}
7781
/>
7882
));
79-
});
83+
}).catch(next);
8084
}
8185
});
8286
});
8387

88+
server.use(raven.middleware.express.errorHandler(config.sentryServer));
89+
90+
if (process.env.NODE_ENV === 'development') {
91+
// only use in development
92+
server.use(errorhandler());
93+
} else {
94+
server.use((req, res) => {
95+
res.status(500);
96+
res.send('OOPS');
97+
});
98+
}
99+
84100
const port = process.env.PORT || 8000;
85101

86102
export default function serve(cb) {
@@ -90,6 +106,7 @@ export default function serve(cb) {
90106
==> ✅ Server is listening at http://localhost:${port}
91107
==> 🎯 API at ${process.env.API_URL}
92108
`);
109+
Object.keys(config).forEach(key => config[key].constructor.name !== 'Object' && console.info(`==> ${key}`, config[key]));
93110

94111
cb && cb(this);
95112
});

server/config/express.js

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ import compression from 'compression';
44
import bodyParser from 'body-parser';
55
import logger from 'morgan';
66
import favicon from 'serve-favicon';
7-
import errorhandler from 'errorhandler';
87
import useragent from 'express-useragent';
98
import cookieParser from 'cookie-parser';
109
import cors from 'cors';
@@ -55,6 +54,4 @@ export default function(server) {
5554
server.use('/api', (req, res) => {
5655
proxyApi.web(req, res);
5756
});
58-
59-
// server.use(errorhandler()); // Must be last!
6057
}

src/config.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@ module.exports = Object.assign({
1414
host: process.env.HOST || 'localhost',
1515
port: process.env.PORT,
1616
api: process.env.API_URL,
17+
sentryClient: process.env.SENTRY_KEY_CLIENT,
18+
sentryServer: process.env.SENTRY_KEY_SERVER,
1719
app: {
1820
head: {
1921
titleTemplate: `%s - ${title}`,

src/helpers/Html.js

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,13 @@
11
import React from 'react';
2+
import ReactDOM from 'react-dom/server';
23
import Helmet from 'react-helmet';
34
import serialize from 'serialize-javascript';
45

56
class Html extends React.Component {
67
render() {
78
const { store, component, assets } = this.props;
9+
const content = component ? ReactDOM.renderToString(component) : '';
810
const head = Helmet.rewind();
9-
console.log(assets.styles);
1011

1112
return (
1213
<html>
@@ -33,7 +34,7 @@ class Html extends React.Component {
3334
<style id="fonts" />
3435
</head>
3536
<body>
36-
<div id="app" dangerouslySetInnerHTML={{__html: component}} />
37+
<div id="app" dangerouslySetInnerHTML={{__html: content}} />
3738

3839
<script
3940
dangerouslySetInnerHTML={{
@@ -79,6 +80,7 @@ class Html extends React.Component {
7980
}`
8081
}} />
8182
<script dangerouslySetInnerHTML={{__html: `window.__data=${serialize(store.getState())};`}} charSet="UTF-8"/>
83+
<script src="https://cdn.ravenjs.com/3.0.4/raven.min.js" />
8284
{Object.keys(assets.javascript).map((script, i) =>
8385
<script src={assets.javascript[script]} key={i}/>
8486
)}

webpack/dev.config.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,8 @@ module.exports = {
7070
'process.env.BROWSER': true,
7171
'process.env.API_URL': JSON.stringify(process.env.API_URL),
7272
'process.env.SEGMENTS_KEY': JSON.stringify(process.env.SEGMENTS_KEY),
73+
'process.env.SENTRY_KEY_CLIENT': JSON.stringify(process.env.SENTRY_KEY_CLIENT),
74+
'process.env.SENTRY_KEY_SERVER': JSON.stringify(process.env.SENTRY_KEY_SERVER),
7375
__SERVER__: false,
7476
__CLIENT__: true,
7577
__DEVELOPMENT__: true,

webpack/prod.config.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,8 @@ module.exports = {
7979
'process.env.BROWSER': true,
8080
'process.env.API_URL': JSON.stringify(process.env.API_URL),
8181
'process.env.SEGMENTS_KEY': JSON.stringify(process.env.SEGMENTS_KEY),
82+
'process.env.SENTRY_KEY_CLIENT': JSON.stringify(process.env.SENTRY_KEY_CLIENT),
83+
'process.env.SENTRY_KEY_SERVER': JSON.stringify(process.env.SENTRY_KEY_SERVER),
8284
'process.env.NODE_ENV': JSON.stringify(process.env.NODE_ENV),
8385
__SERVER__: false,
8486
__CLIENT__: true,

0 commit comments

Comments
 (0)