# all files / keystone/lib/core/ redirect.js

44.44% Statements 4/9
0% Branches 0/9
0% Functions 0/1
44.44% Lines 4/9

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    281×
    1×

    1×

    1×
     var _ = require('lodash');
    var utils = require('keystone-utils');

    /**
     * Adds one or more redirections (urls that are redirected when no matching
     * routes are found, before treating the request as a 404)
     *
     * #### Example:
     * 		keystone.redirect('/old-route', 'new-route');
     *
     * 		// or
     *
     * 		keystone.redirect({
     * 			'old-route': 'new-route'
     * 		});
     */

    function redirect () {
    	if (arguments.length === 1 && utils.isObject(arguments[0])) {
    		_.extend(this._redirects, arguments[0]);
    	} else if (arguments.length === 2 && typeof arguments[0] === 'string' && typeof arguments[1] === 'string') {
    		this._redirects[arguments[0]] = arguments[1];
    	}
    	return this;
    }

    module.exports = redirect;