hostr/web/app.js

92 lines
2.6 KiB
JavaScript
Raw Normal View History

2015-07-09 23:01:43 +01:00
import path from 'path';
2015-08-22 16:16:15 +01:00
import Router from 'koa-router';
import csrf from 'koa-csrf';
2015-07-09 23:01:43 +01:00
import views from 'koa-views';
2015-08-22 13:35:06 +01:00
import stats from 'koa-statsd';
2015-08-22 16:16:15 +01:00
import redis from '../lib/redis';
import koaRedis from 'koa-redis'
2015-07-09 23:01:43 +01:00
import session from 'koa-generic-session';
import co from 'co';
2015-08-22 13:35:06 +01:00
import StatsD from 'statsy';
2015-07-09 23:01:43 +01:00
// waiting for PR to be merged, can remove swig dependency when done
import errors from '../lib/koa-error';
import * as index from './routes/index';
import * as file from './routes/file';
import * as pro from './routes/pro';
import * as user from './routes/user';
2015-08-22 13:35:06 +01:00
2015-07-09 23:01:43 +01:00
import debugname from 'debug';
const debug = debugname('hostr-web');
2015-08-22 16:16:15 +01:00
const router = new Router();
router.use(errors({template: path.join(__dirname, 'public', '404.html')}));
2015-07-09 23:01:43 +01:00
2015-08-09 17:21:39 +01:00
let statsdOpts = {prefix: 'hostr-web', host: process.env.STATSD_HOST || 'localhost'};
let statsd = new StatsD(statsdOpts);
2015-08-22 16:16:15 +01:00
router.use(function* (next) {
2015-08-09 17:21:39 +01:00
this.statsd = statsd;
yield next;
});
2015-08-22 16:16:15 +01:00
router.use(stats(statsdOpts));
2015-07-09 23:01:43 +01:00
2015-08-22 16:16:15 +01:00
router.use(session({
store: koaRedis({client: redis().client})
}));
2015-07-09 23:01:43 +01:00
2015-08-22 16:16:15 +01:00
router.use(function* (next){
2015-07-09 23:01:43 +01:00
this.state = {
2015-08-22 16:16:15 +01:00
session: this.session,
2015-07-09 23:01:43 +01:00
apiURL: process.env.API_URL,
baseURL: process.env.BASE_URL,
stripePublic: process.env.STRIPE_PUBLIC_KEY
};
yield next;
});
2015-08-22 16:16:15 +01:00
router.use(views('views', {
2015-07-09 23:01:43 +01:00
default: 'ejs'
}));
2015-08-22 16:16:15 +01:00
router.get('/', index.main);
router.get('/account', index.main);
router.get('/billing', index.main);
router.get('/pro', index.main);
router.get('/signin', user.signin);
router.post('/signin', user.signin);
router.get('/signup', user.signup);
router.post('/signup', user.signup);
router.get('/logout', user.logout);
router.post('/logout', user.logout);
router.get('/forgot', user.forgot);
router.get('/forgot/:token', user.forgot);
router.post('/forgot/:token', user.forgot);
router.post('/forgot', user.forgot);
router.get('/activate/:code', user.activate);
router.get('/terms', index.staticPage);
router.get('/privacy', index.staticPage);
router.get('/pricing', index.staticPage);
router.get('/apps', index.staticPage);
router.get('/stats', index.staticPage);
router.post('/pro/create', pro.create);
router.post('/pro/cancel', pro.cancel);
router.get('/:id', file.landing);
router.get('/file/:id/:name', file.get);
router.get('/file/:size/:id/:name', file.get);
router.get('/files/:id/:name', file.get);
router.get('/download/:id/:name', function* (id) {
2015-07-09 23:01:43 +01:00
this.redirect('/' + id);
2015-08-22 16:16:15 +01:00
});
2015-07-09 23:01:43 +01:00
2015-08-22 16:16:15 +01:00
router.get('/updaters/mac', function* () {
2015-07-09 23:01:43 +01:00
this.redirect('/updaters/mac.xml');
2015-08-22 16:16:15 +01:00
});
router.get('/updaters/mac/changelog', function* () {
2015-08-11 21:54:55 +01:00
yield this.render('mac-update-changelog');
2015-08-22 16:16:15 +01:00
});
2015-07-09 23:01:43 +01:00
2015-08-22 16:16:15 +01:00
export default router;