+ redirect table support

This commit is contained in:
tmshv committed 2016-02-27 19:42:44 +03:00
1 parent 80719055b3
commit 26c0534372
4 files changed
+41 -1

No files matched your search

+6
View File
@@ -0,0 +1,6 @@
/document/statue-2013 https://static.shburg.org/art/uploads/ustav-shkoly-2013.pdf
/document/edu-license https://static.shburg.org/art/uploads/obrazovatelnaya-lizenziya.pdf
/document/gov-certificate https://static.shburg.org/art/uploads/svidetelstvo-na-pomeschenie.pdf
/document/VAT https://static.shburg.org/art/uploads/inn.pdf
/document/EGRYL1 https://static.shburg.org/art/uploads/egryul.pdf
/document/EGRYL2 https://static.shburg.org/art/uploads/egryul.pdf
1 /document/statue-2013 https://static.shburg.org/art/uploads/ustav-shkoly-2013.pdf
2 /document/edu-license https://static.shburg.org/art/uploads/obrazovatelnaya-lizenziya.pdf
3 /document/gov-certificate https://static.shburg.org/art/uploads/svidetelstvo-na-pomeschenie.pdf
4 /document/VAT https://static.shburg.org/art/uploads/inn.pdf
5 /document/EGRYL1 https://static.shburg.org/art/uploads/egryul.pdf
6 /document/EGRYL2 https://static.shburg.org/art/uploads/egryul.pdf
+13 -1
View File
@@ -37,4 +37,16 @@ export default Object.keys(privateData)
.reduce((config, key) => { .reduce((config, key) => {
config[key] = privateData[key]; config[key] = privateData[key];
return config; return config;
}, config); }, config);
let redirectPath = path.join(__dirname, '../redirect.tsv');
export const redirectionTable = fs.readFileSync(redirectPath, 'utf-8')
.split('\n')
.map(row => row.split(/\s+/))
.map(row => {
let [from, to] = row;
return {
'url': from,
'redirect': to
}
});
+19
View File
@@ -0,0 +1,19 @@
/**
*
* @param redirectionTable
* [{String url, String redirect}, ...]
* @returns {*}
*/
export function redirect(redirectionTable) {
return function *(next) {
let path = this.request.path;
let record = redirectionTable.find(i => i.url === path);
if(record){
this.redirect(record.redirect);
return;
}
yield next;
};
}
+3
View File
@@ -10,7 +10,9 @@ import helmet from 'koa-helmet';
import bodyParser from 'koa-bodyparser'; import bodyParser from 'koa-bodyparser';
import config from './config'; import config from './config';
import {redirectionTable} from './config';
import {index, queryObject} from './routes'; import {index, queryObject} from './routes';
import {redirect} from './routes/redirect';
import sitemap from './routes/sitemap'; import sitemap from './routes/sitemap';
import schedule from './routes/schedule'; import schedule from './routes/schedule';
@@ -42,6 +44,7 @@ app.use(function *(next) {
app.use(prerender(config.prerender)); app.use(prerender(config.prerender));
app.use(serve(path.join(__dirname, '../public'))); app.use(serve(path.join(__dirname, '../public')));
app.use(serve(path.join(__dirname, 'templates'))); app.use(serve(path.join(__dirname, 'templates')));
app.use(redirect(redirectionTable));
app.use(helmet()); app.use(helmet());
app.use(queryObject()); app.use(queryObject());
app.use(route.get('/', index())); app.use(route.get('/', index()));