Refactor route functions in BaseService (#2860)

The route helper functions are fairly well isolated from the rest of BaseService, with a few convenient entry points. They are easier to test in isolation.

The way the code was written before, `pathToRegexp` was invoked once for every request, which seems inefficient.

`route` was validated when it was used, though it seems more helpful to validate it up front.

This breaks out `_makeFullUrl`, `_regex`, `_regexFromPath` into new helper functions `makeFullUrl`, `assertValidRoute`, `prepareRoute`, and `namedParamsForMatch`.

It adds validation to route, and updates the services without patterns to include one, in order to pass the new validation rules.
This commit is contained in:
Paul Melnikow
2019-01-26 02:38:12 -05:00
committed by GitHub
parent bf5438f457
commit 47e8cc3de3
55 changed files with 283 additions and 214 deletions

View File

@@ -20,6 +20,7 @@ class PuppetforgeModuleVersion extends LegacyService {
static get route() {
return {
base: 'puppetforge/v',
pattern: ':user/:moduleName',
}
}
@@ -43,6 +44,7 @@ class PuppetforgeModulePdkVersion extends LegacyService {
static get route() {
return {
base: 'puppetforge/pdk-version',
pattern: ':user/:moduleName',
}
}
@@ -50,7 +52,6 @@ class PuppetforgeModulePdkVersion extends LegacyService {
return [
{
title: 'Puppet Forge PDK version',
pattern: ':user/:moduleName',
namedParams: {
user: 'tragiccode',
moduleName: 'azure_key_vault',
@@ -75,6 +76,7 @@ class PuppetforgeModuleDownloads extends LegacyService {
static get route() {
return {
base: 'puppetforge/dt',
pattern: ':user/:moduleName',
}
}
@@ -98,6 +100,7 @@ class PuppetforgeModuleEndorsement extends LegacyService {
static get route() {
return {
base: 'puppetforge/e',
pattern: ':user/:moduleName',
}
}
@@ -121,6 +124,7 @@ class PuppetforgeModuleFeedback extends LegacyService {
static get route() {
return {
base: 'puppetforge/f',
pattern: ':user/:moduleName',
}
}

View File

@@ -16,6 +16,7 @@ class PuppetforgeUserReleases extends LegacyService {
static get route() {
return {
base: 'puppetforge/rc',
pattern: ':user',
}
}
@@ -39,6 +40,7 @@ class PuppetforgeUserModules extends LegacyService {
static get route() {
return {
base: 'puppetforge/mc',
pattern: ':user',
}
}