UNPKG

812 BJavaScriptView Raw
1'use strict';
2
3Object.defineProperty(exports, "__esModule", {
4 value: true
5});
6exports.default = {
7 name: 'path',
8
9 lookup: function lookup(req, res, options) {
10 var found = void 0;
11
12 if (req === undefined) {
13 return found;
14 }
15
16 if (options.lookupPath !== undefined && req.params) {
17 found = req.params[options.lookupPath];
18 }
19
20 if (!found && typeof options.lookupFromPathIndex === 'number' && req.originalUrl) {
21 var path = req.originalUrl.split('?')[0];
22 var parts = path.split('/');
23 if (parts[0] === '') {
24 // Handle paths that start with a slash, i.e., '/foo' -> ['', 'foo']
25 parts.shift();
26 }
27
28 if (parts.length > options.lookupFromPathIndex) {
29 found = parts[options.lookupFromPathIndex];
30 }
31 }
32
33 return found;
34 }
35};
\No newline at end of file