Skip to content
Myr

refactor: Refactor middleware, tests (#2005)

Before adoption: this commit came in with the history the project adopted, so no landing records it.

* refactor: test, basic auth, cache * refactor: deno dist files * refactor: formating * refactor: format deno basic-auth * refactor: revert package.json test changes

authored by Aris Kemper · committed by GitHub · parent a00fc56 · Browse files · 4 files+34 added−46 removed
This commit

State

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Diff stats

4 files+34 added−46 removed

  • other:+34 added−46 removed

4 files+34 added−46 removed

modified:deno_dist/middleware/basic-auth/index.ts+4 added-10 removed
modified:deno_dist/middleware/cache/index.ts+13 added-13 removed
modified:src/middleware/basic-auth/index.ts+4 added-10 removed
modified:src/middleware/cache/index.ts+13 added-13 removed
31 unmodified lines
32 return async function cache(c, next) {33 const key = c.req.url34 const cache = await caches.open(options.cacheName)35 const response = await cache.match(key)36 if (!response) {37 await next()38 if (!c.res.ok) {39 return40 }41 addHeader(c)42 const response = c.res.clone()43 if (options.wait) {44 await cache.put(key, response)45 } else {46 c.executionCtx.waitUntil(cache.put(key, response))47 }48 } else {36 if (response) {37 return new Response(response.body, response)38 }3940 await next()41 if (!c.res.ok) {42 return43 }44 addHeader(c)45 const res = c.res.clone()46 if (options.wait) {47 await cache.put(key, res)48 } else {49 c.executionCtx.waitUntil(cache.put(key, res))50 }51 }52}