hostr/web/app.js

86 lines
2.4 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 18:24:39 +01:00
import * as redis from '../lib/redis';
2015-08-22 13:35:06 +01:00
import StatsD from 'statsy';
2016-05-25 21:03:07 +01:00
import errors from 'koa-error';
2015-07-09 23:01:43 +01:00
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-08-22 16:16:15 +01:00
const router = new Router();
2015-08-23 01:05:20 +01:00
2015-08-22 23:07:34 +01:00
router.use(errors({template: path.join(__dirname, 'public', 'error.html')}));
2015-07-09 23:01:43 +01:00
2015-08-30 18:35:05 +02:00
const statsdOpts = {prefix: 'hostr-web', host: process.env.STATSD_HOST};
2015-08-22 18:24:39 +01:00
router.use(stats(statsdOpts));
2015-08-23 22:12:32 +01:00
const statsd = new StatsD(statsdOpts);
router.use(function* statsMiddleware(next) {
2015-08-09 17:21:39 +01:00
this.statsd = statsd;
yield next;
});
2015-07-09 23:01:43 +01:00
2015-08-22 18:24:39 +01:00
router.use(redis.sessionStore());
2015-07-09 23:01:43 +01:00
2015-08-23 22:12:32 +01:00
router.use(function* stateMiddleware(next) {
2015-07-09 23:01:43 +01:00
this.state = {
2015-08-22 16:16:15 +01:00
session: this.session,
2015-08-30 18:35:05 +02:00
baseURL: process.env.WEB_BASE_URL,
apiURL: process.env.API_BASE_URL,
2015-08-23 22:12:32 +01:00
stripePublic: process.env.STRIPE_PUBLIC_KEY,
2015-07-09 23:01:43 +01:00
};
yield next;
});
2015-08-22 23:07:34 +01:00
router.use(csrf());
2015-08-22 16:16:15 +01:00
router.use(views('views', {
2015-08-23 22:12:32 +01:00
default: 'ejs',
2015-07-09 23:01:43 +01:00
}));
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);
2015-08-23 22:12:32 +01:00
router.get('/download/:id/:name', function* downloadRedirect(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-23 22:12:32 +01:00
router.get('/updaters/mac', function* macUpdater() {
2015-07-09 23:01:43 +01:00
this.redirect('/updaters/mac.xml');
2015-08-22 16:16:15 +01:00
});
2015-08-23 22:12:32 +01:00
router.get('/updaters/mac/changelog', function* macChangelog() {
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;