Fix Raven

This commit is contained in:
Jonathan Cremin 2018-06-02 19:01:31 +00:00
parent bb5189c9ed
commit 7607759e3f
4 changed files with 17 additions and 25 deletions

View file

@ -9,38 +9,30 @@ It has been through many iterations, but in its current incarnation Hostr uses [
### Dependencies
Everything is taken care of by an `npm install`.
Everything is taken care of by an `make build`.
### Enviroment Variable Configuration
See [`.env.example`](.env.example). Copy it to `.env`, modify and `source .env` for development. [autoenv](https://github.com/kennethreitz/autoenv) is pretty nice for doing this automatically when you `cd` into your work directory.
### Deploying to Heroku
You'll need to add Heroku Redis and a MongoDB addon.
See [`.envrc.example`](.envrc.example). Copy it to `.envrc`, modify and `source .envrc` for development. [direnv](https://github.com/direnv/direnv) is pretty nice for doing this automatically when you `cd` into your work directory.
## Usage
### Start the app
```
$ npm start
$ make docker-compose-up
```
This will install and build the frontend too.
Alternatively
### Initialise the environment
```
$ npm run watch
$ make init migrate
```
Will watch your JS and CSS for changes, rebuild them, and reload the server.
### Run the tests
```
$ npm test
$ make test
```
Running the tests will also set the indexes required for Mongo.

View file

@ -49,8 +49,8 @@ router.use(async (ctx, next) => {
};
} else if (!err.status) {
debug(err);
if (ctx.raven) {
ctx.raven.captureError(err);
if (ctx.Raven) {
ctx.Raven.captureException(err);
}
throw err;
} else {

View file

@ -77,7 +77,7 @@ export async function events(ctx) {
} catch (err) {
debug('Invalid JSON for socket auth');
ctx.websocket.send('Invalid authentication message. Bad JSON?');
ctx.raven.captureError(err);
ctx.Raven.captureException(err);
}
try {
const reply = await ctx.redis.get(json.authorization);
@ -90,7 +90,7 @@ export async function events(ctx) {
}
} catch (err) {
debug(err);
ctx.raven.captureError(err);
ctx.Raven.captureException(err);
}
}));
});

14
app.js
View file

@ -8,7 +8,7 @@ import bodyparser from 'koa-bodyparser';
import websockify from 'koa-websocket';
import helmet from 'koa-helmet';
import session from 'koa-session';
import raven from 'raven';
import Raven from 'raven';
import debugname from 'debug';
import * as redis from './lib/redis';
import api, { ws } from './api/app';
@ -20,14 +20,14 @@ const app = websockify(new Koa());
app.keys = [process.env.COOKIE_KEY];
if (process.env.SENTRY_DSN) {
const ravenClient = new raven.Client(process.env.SENTRY_DSN);
ravenClient.patchGlobal();
Raven.config(process.env.SENTRY_DSN);
Raven.install();
app.use(async (ctx, next) => {
this.raven = ravenClient;
this.Raven = Raven;
await next();
});
app.ws.use(async (ctx, next) => {
this.raven = ravenClient;
this.Raven = Raven;
await next();
});
}
@ -43,8 +43,8 @@ app.use(async (ctx, next) => {
try {
await next();
} catch (err) {
if (!err.statusCode && ctx.raven) {
ctx.raven.captureError(err);
if (!err.statusCode && process.env.SENTRY_DSN) {
Raven.captureException(err);
}
throw err;
}