Skip to content
This repository was archived by the owner on Jul 31, 2025. It is now read-only.

Commit ecc1fa9

Browse files
author
v1rtl
committed
dep bump
1 parent d415599 commit ecc1fa9

File tree

4 files changed

+41
-48
lines changed

4 files changed

+41
-48
lines changed

app.ts

Lines changed: 31 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -22,38 +22,38 @@ declare global {
2222
}
2323
}
2424

25-
export const renderTemplate = <O = any, Res extends Response = Response>(res: Res, app: App) => (
26-
file: string,
27-
data?: Record<string, any>,
28-
options?: TemplateEngineOptions<O>
29-
): Response => {
30-
app.render(
31-
file,
32-
data,
33-
(err: unknown, html: unknown) => {
34-
if (err) throw err
35-
36-
res.send(html)
37-
},
38-
options
39-
)
40-
41-
return res
42-
}
25+
export const renderTemplate =
26+
<O = any, Res extends Response = Response>(res: Res, app: App) =>
27+
(file: string, data?: Record<string, any>, options?: TemplateEngineOptions<O>): Response => {
28+
app.render(
29+
file,
30+
data,
31+
(err: unknown, html: unknown) => {
32+
if (err) throw err
33+
34+
res.send(html)
35+
},
36+
options
37+
)
38+
39+
return res
40+
}
4341

4442
/**
4543
* Execute handler with passed `req` and `res`. Catches errors and resolves async handlers.
4644
* @param h
4745
*/
48-
export const applyHandler = <Req, Res>(h: Handler<Req, Res>) => async (req: Req, res: Res, next: NextFunction) => {
49-
try {
50-
if (h.constructor.name === 'AsyncFunction') {
51-
await h(req, res, next)
52-
} else h(req, res, next)
53-
} catch (e) {
54-
next(e)
46+
export const applyHandler =
47+
<Req, Res>(h: Handler<Req, Res>) =>
48+
async (req: Req, res: Res, next: NextFunction) => {
49+
try {
50+
if (h.constructor.name === 'AsyncFunction') {
51+
await h(req, res, next)
52+
} else h(req, res, next)
53+
} catch (e) {
54+
next(e)
55+
}
5556
}
56-
}
5757

5858
/**
5959
* tinyhttp App has a few settings for toggling features
@@ -119,7 +119,8 @@ export class App<
119119
Res extends Response<RenderOptions> = Response<RenderOptions>
120120
>
121121
extends Router<App, Req, Res>
122-
implements tinyhttp.Application {
122+
implements tinyhttp.Application
123+
{
123124
middleware: Middleware<Req>[] = []
124125
locals: Record<string, string> = {}
125126
noMatchHandler: Handler
@@ -221,7 +222,7 @@ export class App<
221222

222223
const path = typeof base === 'string' ? base : '/'
223224

224-
let regex: { keys: string[]; pattern: RegExp } | undefined
225+
let regex: { keys: string[] | boolean; pattern: RegExp } | undefined
225226

226227
for (const fn of fns) {
227228
if (fn instanceof App) {
@@ -312,14 +313,14 @@ export class App<
312313

313314
if (type === 'route') req.params = getURLParams(regex, pathname)
314315

315-
await applyHandler<Req, Res>((handler as unknown) as Handler<Req, Res>)(req, res, next)
316+
await applyHandler<Req, Res>(handler as unknown as Handler<Req, Res>)(req, res, next)
316317
}
317318

318319
let idx = 0
319320

320321
next = next || ((err: any) => (err ? this.onError(err, req) : loop()))
321322

322-
const loop = () => idx < mw.length && handle(mw[idx++])(req, (res as unknown) as Res, next as NextFunction)
323+
const loop = () => idx < mw.length && handle(mw[idx++])(req, res as unknown as Res, next as NextFunction)
323324

324325
loop()
325326

deps.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,9 @@ export { isIP } from 'https://deno.land/x/isIP@1.0.0/mod.ts'
88
export { Accepts } from 'https://deno.land/x/accepts@2.1.0/mod.ts'
99
export { encodeUrl } from 'https://deno.land/x/encodeurl@1.0.0/mod.ts'
1010
export { charset, contentType, lookup } from 'https://deno.land/x/media_types@v2.8.4/mod.ts'
11-
export { default as rg } from 'https://esm.sh/regexparam'
11+
export { default as rg } from 'https://deno.land/x/regexparam@v1.3.0/src/index.js'
1212
export { forwarded } from 'https://deno.land/x/forwarded@0.0.5/mod.ts'
13-
export * from 'https://deno.land/x/proxy_addr@0.0.3/mod.ts'
13+
export * from 'https://deno.land/x/proxy_addr@0.0.4/mod.ts'
1414
import type { ServerRequest as Req, Response as ServerResponse } from 'https://deno.land/std@0.97.0/http/server.ts'
1515

1616
interface Res extends ServerResponse {

utils/compileTrust.ts

Lines changed: 6 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -5,22 +5,14 @@ type TrustValue = ((...args: any[]) => any) | boolean | string | number | string
55
export function compileTrust(value: TrustValue) {
66
if (typeof value === 'function') return value
77

8-
if (value === true) {
9-
// Support plain true / false
10-
return () => true
11-
}
8+
// Support plain true / false
9+
if (value === true) return () => true
1210

13-
if (typeof value === 'number') {
14-
// Support trusting hop count
15-
return function (_: unknown, i: number) {
16-
return i < ((value as unknown) as number)
17-
}
18-
}
11+
// Support trusting hop count
12+
if (typeof value === 'number') return (_: unknown, i: number) => i < (value as unknown as number)
1913

20-
if (typeof value === 'string') {
21-
// Support comma-separated values
22-
value = value.split(/ *, */)
23-
}
14+
// Support comma-separated values
15+
if (typeof value === 'string') value = value.split(/ *, */)
2416

2517
return compile(value || [])
2618
}

utils/parseUrl.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { parse } from 'https://deno.land/std@0.97.0/node/querystring.ts'
22

33
type Regex = {
4-
keys: string[]
4+
keys: string[] | boolean
55
pattern: RegExp
66
}
77

@@ -11,7 +11,7 @@ export const getURLParams = (r: Regex, reqUrl = '/'): URLParams => {
1111

1212
const params: URLParams = {}
1313

14-
if (matches) for (let i = 0; i < keys.length; i++) params[keys[i]] = matches[i + 1]
14+
if (matches && Array.isArray(keys)) for (let i = 0; i < keys.length; i++) params[keys[i]] = matches[i + 1]
1515

1616
return params
1717
}

0 commit comments

Comments
 (0)