Skip to content

Commit

Permalink
Consume path from req[PATH] [major]
Browse files Browse the repository at this point in the history
  • Loading branch information
overlookmotel committed May 8, 2020
1 parent baa626b commit 41b63cf
Show file tree
Hide file tree
Showing 7 changed files with 151 additions and 87 deletions.
5 changes: 3 additions & 2 deletions lib/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ const Plugin = require('@overlook/plugin'),
{INIT_PROPS, INIT_ROUTE, IS_INITIALIZED} = require('@overlook/route'),
pluginMatch = require('@overlook/plugin-match'),
pluginOrdered = require('@overlook/plugin-ordered'),
{PATH} = require('@overlook/plugin-request'),
{MATCH, HANDLE_MATCH} = pluginMatch,
{IS_BEFORE} = pluginOrdered,
{isString} = require('is-it-type'),
Expand Down Expand Up @@ -86,7 +87,7 @@ function extend(Route) {

// Get path to match against
let path = req[PATH_UNCONSUMED];
if (path === undefined) path = req.url;
if (path === undefined) path = req[PATH];

// Check if path matches

Expand Down Expand Up @@ -151,7 +152,7 @@ function extend(Route) {
[HANDLE_MATCH](req, match) {
// Record that part consumed
const pathOld = req[PATH_UNCONSUMED];
req[PATH_UNCONSUMED] = (pathOld === undefined ? req.url : pathOld)
req[PATH_UNCONSUMED] = (pathOld === undefined ? req[PATH] : pathOld)
.slice(match.pathConsumed.length);

// Record params
Expand Down
28 changes: 13 additions & 15 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,13 @@
"@overlook/plugin": "^0.2.3",
"@overlook/plugin-match": "^0.7.1",
"@overlook/plugin-ordered": "^0.4.2",
"@overlook/plugin-request": "^0.1.0",
"@overlook/route": "^0.5.1",
"has-own-prop": "^2.0.0",
"is-it-type": "^4.0.0"
},
"devDependencies": {
"@overlook/plugin-serve-http": "^0.1.2",
"@overlook/plugin-serve-http": "^0.3.0",
"@overlook/plugin-start": "^0.1.2",
"@overlookmotel/eslint-config": "^7.1.2",
"@overlookmotel/eslint-config-jest": "^4.0.1",
Expand Down
31 changes: 16 additions & 15 deletions test/integration/match.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
// Modules
const Route = require('@overlook/route'),
{HANDLE_ROUTE} = require('@overlook/plugin-match'),
{PATH} = require('@overlook/plugin-request'),
pathPlugin = require('@overlook/plugin-path'),
{PATH_PART, PARAMS} = pathPlugin;

Expand Down Expand Up @@ -115,7 +116,7 @@ describe('Matching', () => { // eslint-disable-line jest/lowercase-name
describe("when root route has [PATH_PART] = ''", () => {
let req;
beforeEach(() => {
req = {url: '/'};
req = {[PATH]: '/'};
router.handle(req);
});

Expand All @@ -134,7 +135,7 @@ describe('Matching', () => { // eslint-disable-line jest/lowercase-name
describe('when root route is wildcard', () => {
let req;
beforeEach(() => {
req = {url: '/'};
req = {[PATH]: '/'};
router[PATH_PART] = '*';
router.handle(req);
});
Expand All @@ -160,7 +161,7 @@ describe('Matching', () => { // eslint-disable-line jest/lowercase-name
describe('matching 1st named child', () => {
let req;
beforeEach(() => {
req = {url: '/a'};
req = {[PATH]: '/a'};
router.handle(req);
});

Expand All @@ -179,7 +180,7 @@ describe('Matching', () => { // eslint-disable-line jest/lowercase-name
describe('matching 2nd named child', () => {
let req;
beforeEach(() => {
req = {url: '/b'};
req = {[PATH]: '/b'};
router.handle(req);
});

Expand All @@ -198,7 +199,7 @@ describe('Matching', () => { // eslint-disable-line jest/lowercase-name
describe('matching no named child', () => {
let req;
beforeEach(() => {
req = {url: '/p'};
req = {[PATH]: '/p'};
router.handle(req);
});

Expand All @@ -221,7 +222,7 @@ describe('Matching', () => { // eslint-disable-line jest/lowercase-name
removedIndex = router.children.indexOf(routeP);
router.children.splice(removedIndex, 1);

req = {url: '/w'};
req = {[PATH]: '/w'};
router.handle(req);
});

Expand All @@ -248,7 +249,7 @@ describe('Matching', () => { // eslint-disable-line jest/lowercase-name
describe('matching 1st named child', () => {
let req;
beforeEach(() => {
req = {url: '/a/c'};
req = {[PATH]: '/a/c'};
router.handle(req);
});

Expand All @@ -267,7 +268,7 @@ describe('Matching', () => { // eslint-disable-line jest/lowercase-name
describe('matching 2nd named child', () => {
let req;
beforeEach(() => {
req = {url: '/a/d'};
req = {[PATH]: '/a/d'};
router.handle(req);
});

Expand All @@ -286,7 +287,7 @@ describe('Matching', () => { // eslint-disable-line jest/lowercase-name
describe('matching no named child', () => {
let req;
beforeEach(() => {
req = {url: '/a/ap'};
req = {[PATH]: '/a/ap'};
router.handle(req);
});

Expand All @@ -305,7 +306,7 @@ describe('Matching', () => { // eslint-disable-line jest/lowercase-name
describe('matching no named child and no param child', () => {
let req;
beforeEach(() => {
req = {url: '/b/w'};
req = {[PATH]: '/b/w'};
router.handle(req);
});

Expand All @@ -326,7 +327,7 @@ describe('Matching', () => { // eslint-disable-line jest/lowercase-name
describe('matching 1st named child', () => {
let req;
beforeEach(() => {
req = {url: '/p/e'};
req = {[PATH]: '/p/e'};
router.handle(req);
});

Expand All @@ -345,7 +346,7 @@ describe('Matching', () => { // eslint-disable-line jest/lowercase-name
describe('matching 2nd named child', () => {
let req;
beforeEach(() => {
req = {url: '/p/f'};
req = {[PATH]: '/p/f'};
router.handle(req);
});

Expand All @@ -364,7 +365,7 @@ describe('Matching', () => { // eslint-disable-line jest/lowercase-name
describe('matching no named child', () => {
let req;
beforeEach(() => {
req = {url: '/p/pp'};
req = {[PATH]: '/p/pp'};
router.handle(req);
});

Expand All @@ -387,7 +388,7 @@ describe('Matching', () => { // eslint-disable-line jest/lowercase-name
removedIndex = routeP.children.indexOf(routePP);
routeP.children.splice(removedIndex, 1);

req = {url: '/p/w'};
req = {[PATH]: '/p/w'};
router.handle(req);
});

Expand Down Expand Up @@ -416,7 +417,7 @@ describe('Matching', () => { // eslint-disable-line jest/lowercase-name
removedIndex = router.children.indexOf(routeP);
router.children.splice(removedIndex, 1);

req = {url: '/w/x'};
req = {[PATH]: '/w/x'};
router.handle(req);
});

Expand Down
Loading

0 comments on commit 41b63cf

Please sign in to comment.