Skip to content
This repository has been archived by the owner on Jun 27, 2024. It is now read-only.

Commit

Permalink
fix outstanding issues
Browse files Browse the repository at this point in the history
  • Loading branch information
boywithkeyboard committed Aug 18, 2023
1 parent 071c81e commit 17ecb84
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 12 deletions.
25 changes: 15 additions & 10 deletions cheetah.ts
Original file line number Diff line number Diff line change
Expand Up @@ -250,15 +250,17 @@ export class cheetah extends base<cheetah>() {
const regex = /^v[1-9][0-9]?$|^100$/

if (this.#versioning.type === 'uri') {
pathname = pathname.replace('/', '')
const arr = pathname.replace('/', '').split('/')

if (regex.test(pathname.split('/')[0])) {
pathname.split('/').shift()
if (regex.test(arr[0])) {
const version = arr[0]

return { version: pathname.split('/')[0], pathname: '/' + pathname }
arr.shift()

return { version, pathname: '/' + arr.join('/') }
}

return { version: this.#versioning.current, pathname: '/' + pathname }
return { version: this.#versioning.current, pathname }
}

const header = headers.get(this.#versioning.header)
Expand All @@ -281,18 +283,18 @@ export class cheetah extends base<cheetah>() {
this.#preflight && request.method === 'HEAD' && r[0] === 'GET'
) {
if (this.#versioning) {
const options = typeof r[3][0] !== 'function' ? r[3][0] : null

const { pathname, version } = this.#parseVersion(request.headers, p)

if (
parseInt(version.replace('v', '')) >
parseInt(this.#versioning.current.replace('v', ''))
) {
return null
break
}

if (options !== null && options.versionRange !== undefined) {
const options = typeof r[3][0] !== 'function' ? r[3][0] : null

if (options?.versionRange !== undefined) {
const result = pathname.match(r[2])

if (!result) {
Expand All @@ -305,7 +307,7 @@ export class cheetah extends base<cheetah>() {
)

if (!gateway) {
return null
break
}

return {
Expand Down Expand Up @@ -376,6 +378,7 @@ export class cheetah extends base<cheetah>() {
runtime: this.#runtime,
oauth: this.#oauth,
versioning: this.#versioning,
gateway: -1,
}

if (this.#extensions.size > 0) {
Expand Down Expand Up @@ -444,6 +447,8 @@ export class cheetah extends base<cheetah>() {
__app.request.pathname,
)

__app.gateway = route?.gateway ?? -1

if (!route) {
if (!this.#notFound) {
throw new Exception('Not Found', undefined, 404)
Expand Down
6 changes: 4 additions & 2 deletions test/routing/versioning.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,8 @@ Deno.test('versioning', async (t) => {
assertEquals(await get('/v1/1'), 'hello from v1')
assertEquals(await get('/v2/1'), 'hello from v2')
assertEquals(await get('/v3/1'), 'hello from v3')
assertEquals(await get('/v4/1') !== 'hello from v4', true)
assertEquals(await get('/v4/1'), 'hello from v4')
assertEquals(await get('/v5/1') !== 'hello from v5', true)

// exact

Expand Down Expand Up @@ -118,7 +119,8 @@ Deno.test('versioning', async (t) => {
assertEquals(await get('/v1/1'), 'hello from v1')
assertEquals(await get('/v2/1'), 'hello from v2')
assertEquals(await get('/v3/1'), 'hello from v3')
assertEquals(await get('/v4/1') !== 'hello from v4', true)
assertEquals(await get('/v4/1'), 'hello from v4')
assertEquals(await get('/v5/1') !== 'hello from v5', true)

// exact

Expand Down

0 comments on commit 17ecb84

Please sign in to comment.