From 05041173fe6a30b4c9b0ca39a455a5496f4964e8 Mon Sep 17 00:00:00 2001 From: thedark1337 Date: Sat, 29 Aug 2015 11:17:33 -0500 Subject: [PATCH] Switched out Koa-frouter for Koa-Router --- routes/{about.js => about/index.js} | 2 +- routes/{alpha.js => alpha/index.js} | 2 +- .../{ambassadors.js => ambassadors/index.js} | 2 +- routes/{commands.js => commands/index.js} | 2 +- routes/{donations.js => donations/index.js} | 2 +- routes/{features.js => features/index.js} | 2 +- routes/index.js | 37 +++++++++++++++++-- routes/index/index.js | 5 +++ routes/{install.js => install/index.js} | 2 +- routes/lang/index.js | 7 ++++ routes/{license.js => license/index.js} | 2 +- routes/{readme.js => readme/index.js} | 2 +- routes/{translate.js => translate/index.js} | 2 +- 13 files changed, 56 insertions(+), 13 deletions(-) rename routes/{about.js => about/index.js} (60%) rename routes/{alpha.js => alpha/index.js} (60%) rename routes/{ambassadors.js => ambassadors/index.js} (63%) rename routes/{commands.js => commands/index.js} (62%) rename routes/{donations.js => donations/index.js} (62%) rename routes/{features.js => features/index.js} (62%) create mode 100644 routes/index/index.js rename routes/{install.js => install/index.js} (61%) create mode 100644 routes/lang/index.js rename routes/{license.js => license/index.js} (61%) rename routes/{readme.js => readme/index.js} (61%) rename routes/{translate.js => translate/index.js} (63%) diff --git a/routes/about.js b/routes/about/index.js similarity index 60% rename from routes/about.js rename to routes/about/index.js index 4ca4fdf..cbc8ad2 100644 --- a/routes/about.js +++ b/routes/about/index.js @@ -1,5 +1,5 @@ 'use strict'; -exports.get = function *() { +module.exports = function *() { yield this.render('about'); }; diff --git a/routes/alpha.js b/routes/alpha/index.js similarity index 60% rename from routes/alpha.js rename to routes/alpha/index.js index 92bc970..62610f2 100644 --- a/routes/alpha.js +++ b/routes/alpha/index.js @@ -1,5 +1,5 @@ 'use strict'; -exports.get = function *() { +module.exports = function *() { yield this.render('alpha'); }; diff --git a/routes/ambassadors.js b/routes/ambassadors/index.js similarity index 63% rename from routes/ambassadors.js rename to routes/ambassadors/index.js index bed4db3..44118eb 100644 --- a/routes/ambassadors.js +++ b/routes/ambassadors/index.js @@ -1,5 +1,5 @@ 'use strict'; -exports.get = function *() { +module.exports = function *() { yield this.render('ambassadors'); }; diff --git a/routes/commands.js b/routes/commands/index.js similarity index 62% rename from routes/commands.js rename to routes/commands/index.js index 3ab9e67..0df6f9a 100644 --- a/routes/commands.js +++ b/routes/commands/index.js @@ -1,5 +1,5 @@ 'use strict'; -exports.get = function *() { +module.exports = function *() { yield this.render('commands'); }; diff --git a/routes/donations.js b/routes/donations/index.js similarity index 62% rename from routes/donations.js rename to routes/donations/index.js index 74bdc59..38ab63b 100644 --- a/routes/donations.js +++ b/routes/donations/index.js @@ -1,5 +1,5 @@ 'use strict'; -exports.get = function *() { +module.exports = function *() { yield this.render('donations'); }; diff --git a/routes/features.js b/routes/features/index.js similarity index 62% rename from routes/features.js rename to routes/features/index.js index 3c77c49..8d50194 100644 --- a/routes/features.js +++ b/routes/features/index.js @@ -1,5 +1,5 @@ 'use strict'; -exports.get = function *() { +module.exports = function *() { yield this.render('features'); }; diff --git a/routes/index.js b/routes/index.js index 0304c3d..7c05080 100644 --- a/routes/index.js +++ b/routes/index.js @@ -1,5 +1,36 @@ 'use strict'; -exports.get = function *() { - yield this.render('index'); -}; +/* Route Dependencies */ + +const bodyParser = require('koa-body-parser'); +const router = require('koa-router')(); + +/* Route Files */ +const about = require('./about'); +const alpha = require('./alpha'); +const ambassadors = require('./ambassadors'); +const commands = require('./commands'); +const donations = require('./donations'); +const features = require('./features'); +const index = require('./index/'); +const install = require('./install'); +const lang = require('./lang'); +const license = require('./license'); +const readme = require('./readme'); +const translate = require('./translate'); + +/* Routes */ +router.get('/', index); +router.get('/about', about); +router.get('/alpha', alpha); +router.get('/ambassadors', ambassadors); +router.get('/commands', commands); +router.get('/donations', donations); +router.get('/features', features); +router.get('/install', install); +router.post('/lang', bodyParser(), lang); +router.get('/license', license); +router.get('/readme', readme); +router.get('/translate', translate); + +module.exports = router; diff --git a/routes/index/index.js b/routes/index/index.js new file mode 100644 index 0000000..88c2408 --- /dev/null +++ b/routes/index/index.js @@ -0,0 +1,5 @@ +'use strict'; + +module.exports = function *() { + yield this.render('index'); +}; diff --git a/routes/install.js b/routes/install/index.js similarity index 61% rename from routes/install.js rename to routes/install/index.js index 4377469..a6f89bd 100644 --- a/routes/install.js +++ b/routes/install/index.js @@ -1,5 +1,5 @@ 'use strict'; -exports.get = function *() { +module.exports = function *() { yield this.render('install'); }; diff --git a/routes/lang/index.js b/routes/lang/index.js new file mode 100644 index 0000000..55175eb --- /dev/null +++ b/routes/lang/index.js @@ -0,0 +1,7 @@ +'use strict'; + +module.exports = function *(next) { + const lang = this.request.body && this.request.body.lang || 'en'; + this.cookies.set('locale', lang); + this.status = 200; +}; diff --git a/routes/license.js b/routes/license/index.js similarity index 61% rename from routes/license.js rename to routes/license/index.js index 493b247..ca2c59b 100644 --- a/routes/license.js +++ b/routes/license/index.js @@ -1,5 +1,5 @@ 'use strict'; -exports.get = function *() { +module.exports = function *() { yield this.render('license'); }; diff --git a/routes/readme.js b/routes/readme/index.js similarity index 61% rename from routes/readme.js rename to routes/readme/index.js index 4377469..a6f89bd 100644 --- a/routes/readme.js +++ b/routes/readme/index.js @@ -1,5 +1,5 @@ 'use strict'; -exports.get = function *() { +module.exports = function *() { yield this.render('install'); }; diff --git a/routes/translate.js b/routes/translate/index.js similarity index 63% rename from routes/translate.js rename to routes/translate/index.js index bfcbf24..ce6999f 100644 --- a/routes/translate.js +++ b/routes/translate/index.js @@ -1,5 +1,5 @@ 'use strict'; -exports.get = function *() { +module.exports = function *() { yield this.render('translators'); };