Fix events stuff, improve errors
This commit is contained in:
parent
3091c6dff6
commit
652fe5c264
6 changed files with 48 additions and 16 deletions
|
@ -46,6 +46,7 @@ router.use('/*',function* (next) {
|
|||
} else {
|
||||
if (!err.status) {
|
||||
debug(err);
|
||||
this.raven.captureError(err);
|
||||
throw err;
|
||||
} else {
|
||||
this.status = err.status;
|
||||
|
@ -73,4 +74,8 @@ router.get('/(.*)', function* () {
|
|||
this.throw(404);
|
||||
});
|
||||
|
||||
export const ws = new Router();
|
||||
|
||||
ws.all('/user', user.events);
|
||||
|
||||
export default router;
|
||||
|
|
|
@ -65,16 +65,23 @@ export function* events() {
|
|||
let json;
|
||||
try{
|
||||
json = JSON.parse(message);
|
||||
} catch(e) {
|
||||
} catch(err) {
|
||||
debug('Invalid JSON for socket auth');
|
||||
this.websocket.send('Invalid authentication message. Bad JSON?');
|
||||
this.raven.captureError(err);
|
||||
}
|
||||
const reply = yield this.redis.get(json.authorization);
|
||||
if (reply) {
|
||||
pubsub.subscribe('/user/' + reply);
|
||||
debug('Subscribed to: /user/%s', reply);
|
||||
} else {
|
||||
this.websocket.send('Invalid authentication token.');
|
||||
try {
|
||||
const reply = yield this.redis.get(json.authorization);
|
||||
if (reply) {
|
||||
pubsub.subscribe('/user/' + reply);
|
||||
this.websocket.send('{"status":"active"}');
|
||||
debug('Subscribed to: /user/%s', reply);
|
||||
} else {
|
||||
this.websocket.send('Invalid authentication token.');
|
||||
}
|
||||
} catch(err) {
|
||||
debug(err);
|
||||
this.raven.captureError(err);
|
||||
}
|
||||
}.bind(this)));
|
||||
});
|
||||
|
|
27
app.js
27
app.js
|
@ -15,6 +15,7 @@ import mongo from './lib/mongo';
|
|||
import * as redis from './lib/redis';
|
||||
import co from 'co';
|
||||
import api from './api/app';
|
||||
import { ws } from './api/app';
|
||||
import web from './web/app';
|
||||
import { init as storageInit } from './lib/storage';
|
||||
storageInit();
|
||||
|
@ -22,14 +23,22 @@ storageInit();
|
|||
import debugname from 'debug';
|
||||
const debug = debugname('hostr');
|
||||
|
||||
const app = websockify(koa());
|
||||
app.keys = [process.env.KEYS || 'INSECURE'];
|
||||
|
||||
if (process.env.SENTRY_DSN) {
|
||||
const ravenClient = new raven.Client(process.env.SENTRY_DSN);
|
||||
ravenClient.patchGlobal();
|
||||
app.use(function* (next) {
|
||||
this.raven = ravenClient;
|
||||
yield next;
|
||||
});
|
||||
app.ws.use(function* (next) {
|
||||
this.raven = ravenClient;
|
||||
yield next;
|
||||
});
|
||||
}
|
||||
|
||||
const app = websockify(koa());
|
||||
app.keys = [process.env.KEYS || 'INSECURE'];
|
||||
|
||||
app.use(helmet());
|
||||
|
||||
app.use(function* (next){
|
||||
|
@ -37,7 +46,14 @@ app.use(function* (next){
|
|||
if(this.req.headers['x-forwarded-proto'] === 'http'){
|
||||
return this.redirect('https://' + this.req.headers.host + this.req.url);
|
||||
}
|
||||
yield next;
|
||||
try {
|
||||
yield next;
|
||||
} catch (err) {
|
||||
if (!err.statusCode) {
|
||||
this.raven.captureError(err);
|
||||
}
|
||||
throw err;
|
||||
}
|
||||
});
|
||||
|
||||
app.use(mongo());
|
||||
|
@ -52,6 +68,9 @@ app.use(serve(path.join(__dirname, 'web/public/'), {maxage: 31536000000}));
|
|||
app.use(api.prefix('/api').routes());
|
||||
app.use(web.prefix('').routes());
|
||||
|
||||
app.ws.use(redis.middleware());
|
||||
app.ws.use(ws.prefix('/api').routes());
|
||||
|
||||
if (!module.parent) {
|
||||
app.listen(process.env.PORT || 4040, function() {
|
||||
debug('Koa HTTP server listening on port ' + (process.env.PORT || 4040));
|
||||
|
|
|
@ -17,6 +17,7 @@ import debugname from 'debug';
|
|||
const debug = debugname('hostr-web');
|
||||
|
||||
const router = new Router();
|
||||
|
||||
router.use(errors({template: path.join(__dirname, 'public', 'error.html')}));
|
||||
|
||||
let statsdOpts = {prefix: 'hostr-web', host: process.env.STATSD_HOST || 'localhost'};
|
||||
|
|
|
@ -4,7 +4,7 @@
|
|||
<meta charset="utf-8">
|
||||
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||
<title ng-bind="Hostr">Hostr - File not found</title>
|
||||
<title ng-bind="Hostr">Hostr - 50x Unexpected Error</title>
|
||||
<link rel="icon" type="image/png" href="/images/favicon.png">
|
||||
<link href='//fonts.googleapis.com/css?family=Lato:300,400' rel='stylesheet' type='text/css'>
|
||||
<link href='//fonts.googleapis.com/css?family=Open+Sans:400,300,600' rel='stylesheet' type='text/css'>
|
||||
|
@ -21,9 +21,9 @@
|
|||
</div>
|
||||
<div class='row vertical-center'>
|
||||
<div class='col-md-12'>
|
||||
<h2>500</h2>
|
||||
<h1>Sorry, It looks like you've hit an unexpected error.</h1>
|
||||
<p class="lead">Refreshing might fix the problem. If not, sit tight! We're on it!</p>
|
||||
<h2>50x</h2>
|
||||
<h1>Sorry, it looks like you've hit an unexpected error.</h1>
|
||||
<p>Refreshing might fix the problem. If not, sit tight! We're on it!</p>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
|
|
@ -4,7 +4,7 @@
|
|||
<meta charset="utf-8">
|
||||
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||
<title ng-bind="Hostr">Hostr - File not found</title>
|
||||
<title ng-bind="Hostr">Hostr - Error Encountered</title>
|
||||
<link rel="icon" type="image/png" href="/images/favicon.png">
|
||||
<link href='//fonts.googleapis.com/css?family=Lato:300,400' rel='stylesheet' type='text/css'>
|
||||
<link href='//fonts.googleapis.com/css?family=Open+Sans:400,300,600' rel='stylesheet' type='text/css'>
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue