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';
|
2015-08-10 11:44:47 +01:00
|
|
|
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';
|
|
|
|
import StatsD from 'statsy';
|
2016-05-25 21:03:07 +01:00
|
|
|
import errors from 'koa-error';
|
2016-06-02 21:06:52 +01:00
|
|
|
import * as redis from '../lib/redis';
|
2015-07-09 23:01:43 +01:00
|
|
|
import * as index from './routes/index';
|
|
|
|
import * as file from './routes/file';
|
|
|
|
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
|
|
|
|
2016-06-02 21:06:52 +01:00
|
|
|
router.use(errors({
|
|
|
|
engine: 'ejs',
|
2016-06-06 15:37:00 +01:00
|
|
|
template: path.join(__dirname, 'public', 'error.html'),
|
2016-06-02 21:06:52 +01:00
|
|
|
}));
|
2015-07-09 23:01:43 +01:00
|
|
|
|
2016-06-06 15:37:00 +01: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());
|
|
|
|
|
2016-06-02 21:06:52 +01:00
|
|
|
router.use(views(path.join(__dirname, 'views'), {
|
2016-06-06 15:37:00 +01:00
|
|
|
extension: '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.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) {
|
2016-06-06 15:37:00 +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;
|