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