Skip to content

Commit f04319f

Browse files
committed
Fix and test for #121
1 parent b2a8503 commit f04319f

File tree

2 files changed

+11
-1
lines changed

2 files changed

+11
-1
lines changed

index.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -467,7 +467,7 @@ class API {
467467
fn(this,options)
468468

469469
// Remove the last prefix
470-
this._prefix = this._prefix.slice(0,-(prefix.length))
470+
if(prefix.length) this._prefix = this._prefix.slice(0,-(prefix.length))
471471

472472
} // end register
473473

test/register.js

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -136,4 +136,14 @@ describe('Register Tests:', function() {
136136
expect(result).to.deep.equal({ multiValueHeaders: { 'content-type': ['application/json'] }, statusCode: 200, body: '{"path":"/test-register-no-options","route":"/test-register-no-options","method":"GET"}', isBase64Encoded: false })
137137
}) // end it
138138

139+
it('Base path w/ multiple unprefixed registers', async function() {
140+
const api = require('../index')({
141+
base: 'base-path'
142+
})
143+
api.register((api) => { api.get('/foo', async () => {})}, { prefix: 'fuz'})
144+
api.register((api) => { api.get('/bar', async () => {})})
145+
api.register((api) => { api.get('/baz', async () => {})})
146+
expect(api.routes()).to.deep.equal([["GET", "/base-path/fuz/foo"], ["GET", "/base-path/bar"], ["GET", "/base-path/baz"]])
147+
}) // end it
148+
139149
}) // end ROUTE tests

0 commit comments

Comments
 (0)