Skip to content

Commit

Permalink
bump deps & eliminate lint errors
Browse files Browse the repository at this point in the history
  • Loading branch information
v1rtl committed Jul 5, 2021
1 parent f5ecac7 commit bb680bd
Show file tree
Hide file tree
Showing 12 changed files with 54 additions and 57 deletions.
4 changes: 2 additions & 2 deletions app.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,12 @@
import { Router, serve, Server, rg, pushMiddleware } from './deps.ts'
import { NextFunction, RHandler as Handler, Middleware, UseMethodParams } from './types.ts'
import { onErrorHandler, ErrorHandler } from './onError.ts'
import { setImmediate } from 'https://deno.land/std@0.99.0/node/timers.ts'
import { setImmediate } from 'https://deno.land/std@0.100.0/node/timers.ts'
import type { Request } from './request.ts'
import type { Response } from './response.ts'
import { getURLParams, getPathname } from './utils/parseUrl.ts'
import { extendMiddleware } from './extend.ts'
import * as path from 'https://deno.land/std@0.99.0/path/mod.ts'
import * as path from 'https://deno.land/std@0.100.0/path/mod.ts'

const lead = (x: string) => (x.charCodeAt(0) === 47 ? x : '/' + x)

Expand Down
10 changes: 5 additions & 5 deletions deps.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,18 +7,18 @@ export { vary } from 'https://deno.land/x/vary@1.0.0/mod.ts'
export { isIP } from 'https://deno.land/x/isIP@1.0.0/mod.ts'
export { Accepts } from 'https://deno.land/x/accepts@2.1.0/mod.ts'
export { encodeUrl } from 'https://deno.land/x/encodeurl@1.0.0/mod.ts'
export { charset, contentType, lookup } from 'https://deno.land/x/media_types@v2.9.0/mod.ts'
export { charset, contentType, lookup } from 'https://deno.land/x/media_types@v2.9.1/mod.ts'
export { parse as rg } from 'https://deno.land/x/regexparam@v2.0.0/src/index.js'
export { forwarded } from 'https://deno.land/x/forwarded@0.0.7/mod.ts'
export * from 'https://deno.land/x/proxy_addr@0.0.8/mod.ts'
import type { ServerRequest as Req, Response as ServerResponse } from 'https://deno.land/std@0.99.0/http/server.ts'
export { forwarded } from 'https://deno.land/x/forwarded@0.0.8/mod.ts'
export * from 'https://deno.land/x/proxy_addr@0.0.9/mod.ts'
import type { ServerRequest as Req, Response as ServerResponse } from 'https://deno.land/std@0.100.0/http/server.ts'

interface Res extends ServerResponse {
headers: Headers
}

export type { Req, Res }

export { serve, Server } from 'https://deno.land/std@0.99.0/http/server.ts'
export { serve, Server } from 'https://deno.land/std@0.100.0/http/server.ts'

export { Router, pushMiddleware } from 'https://esm.sh/@tinyhttp/router@1.3.3'
2 changes: 1 addition & 1 deletion examples/jwt/server.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { App } from '../../mod.ts'
import { getNumericDate, Payload, Header, create, verify } from 'https://deno.land/x/djwt@v2.2/mod.ts'
import { readAll } from 'https://deno.land/std@0.99.0/io/util.ts'
import { readAll } from 'https://deno.land/std@0.100.0/io/util.ts'

const SECRET = 'my_secret'

Expand Down
2 changes: 1 addition & 1 deletion extensions/res/cookie.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { Req, Res } from '../../deps.ts'
import * as cookie from 'https://deno.land/std@0.99.0/http/cookie.ts'
import * as cookie from 'https://deno.land/std@0.100.0/http/cookie.ts'

export const setCookie = <Request extends Req = Req, Response extends Res = Res>(req: Request, res: Response) => (
name: string,
Expand Down
2 changes: 1 addition & 1 deletion extensions/res/download.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { contentDisposition } from 'https://esm.sh/@tinyhttp/content-disposition'
import { SendFileOptions, sendFile } from './send/sendFile.ts'
import { extname } from 'https://deno.land/std@0.99.0/path/mod.ts'
import { extname } from 'https://deno.land/std@0.100.0/path/mod.ts'
import { setContentType, setHeader } from './headers.ts'
import { Req, Res } from '../../deps.ts'

Expand Down
75 changes: 36 additions & 39 deletions extensions/res/send/sendFile.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { Req, Res } from '../../../deps.ts'
import { isAbsolute, join, extname } from 'https://deno.land/std@0.99.0/path/mod.ts'
import { isAbsolute, join, extname } from 'https://deno.land/std@0.100.0/path/mod.ts'
import { contentType } from '../../../deps.ts'
import { createETag } from '../utils.ts'
import { send } from './send.ts'
Expand All @@ -22,59 +22,56 @@ export type SendFileOptions = Partial<{
*
* @param res Response
*/
export const sendFile = <Request extends Req = Req, Response extends Res = Res>(req: Request, res: Response) => (
path: string,
opts: SendFileOptions = {}
) => {
const { root, headers = {}, encoding = 'utf-8', ...options } = opts
export const sendFile =
<Request extends Req = Req, Response extends Res = Res>(req: Request, res: Response) =>
(path: string, opts: SendFileOptions = {}) => {
const { root, headers = {}, encoding = 'utf-8', ...options } = opts

if (!isAbsolute(path) && !root) throw new TypeError('path must be absolute')
if (!isAbsolute(path) && !root) throw new TypeError('path must be absolute')

const filePath = root ? join(root, path) : path
const filePath = root ? join(root, path) : path

let stats: Deno.FileInfo
const stats = Deno.statSync(filePath)

stats = Deno.statSync(filePath)
headers['Content-Encoding'] = encoding

headers['Content-Encoding'] = encoding
headers['Last-Modified'] = stats.mtime!.toUTCString()

headers['Last-Modified'] = stats.mtime!.toUTCString()
headers['Content-Type'] = contentType(extname(path)) || 'text/html'

headers['Content-Type'] = contentType(extname(path)) || 'text/html'
headers['ETag'] = createETag(stats)

headers['ETag'] = createETag(stats)
headers['Content-Length'] = `${stats.size}`

headers['Content-Length'] = `${stats.size}`
headers['Content-Security-Policy'] = "default-src 'none'"
headers['X-Content-Type-Options'] = 'nosniff'

headers['Content-Security-Policy'] = "default-src 'none'"
headers['X-Content-Type-Options'] = 'nosniff'
let status = 200

let status = 200
if (req.headers.get('range')) {
status = 206
const [x, y] = req.headers?.get('range')?.replace('bytes=', '').split('-') as [string, string]
const end = (options.end = parseInt(y, 10) || stats.size - 1)
const start = (options.start = parseInt(x, 10) || 0)

if (req.headers.get('range')) {
status = 206
const [x, y] = req.headers?.get('range')?.replace('bytes=', '').split('-') as [string, string]
const end = (options.end = parseInt(y, 10) || stats.size - 1)
const start = (options.start = parseInt(x, 10) || 0)

if (start >= stats.size || end >= stats.size) {
res.status = 416
res.headers?.set('Content-Range', `bytes */${stats.size}`)
req.respond({})
return res
if (start >= stats.size || end >= stats.size) {
res.status = 416
res.headers?.set('Content-Range', `bytes */${stats.size}`)
req.respond({})
return res
}
headers['Content-Range'] = `bytes ${start}-${end}/${stats.size}`
headers['Content-Length'] = `${end - start + 1}`
headers['Accept-Ranges'] = 'bytes'
}
headers['Content-Range'] = `bytes ${start}-${end}/${stats.size}`
headers['Content-Length'] = `${end - start + 1}`
headers['Accept-Ranges'] = 'bytes'
}

for (const [k, v] of Object.entries(headers)) res.headers?.set(k, v)
for (const [k, v] of Object.entries(headers)) res.headers?.set(k, v)

res.status = status
res.status = status

const file = Deno.openSync(filePath, { read: true, ...options })
const file = Deno.openSync(filePath, { read: true, ...options })

send(req, res)(file)
send(req, res)(file)

return res
}
return res
}
6 changes: 3 additions & 3 deletions extensions/res/utils.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { format, parse } from 'https://deno.land/x/content_type/mod.ts'
import { etag as eTag } from 'https://deno.land/x/opine@1.5.3/src/utils/etag.ts'
import { format, parse } from 'https://deno.land/x/content_type@1.0.1/mod.ts'
import { etag as eTag } from 'https://deno.land/x/opine@1.5.4/src/utils/etag.ts'
import { lookup } from '../../deps.ts'

export const createETag = (body: Parameters<typeof eTag>[0]) => {
Expand All @@ -21,7 +21,7 @@ export function acceptParams(str: string, index?: number) {
const ret: {
value: string
quality: number
params: Record<string, any>
params: Record<string, string>
originalIndex?: number
} = { value: parts[0], quality: 1, params: {}, originalIndex: index }

Expand Down
2 changes: 1 addition & 1 deletion request.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// deno-lint-ignore-file
import { ServerRequest } from 'https://deno.land/std@0.99.0/http/server.ts'
import { ServerRequest } from 'https://deno.land/std@0.100.0/http/server.ts'
import { App } from './app.ts'
import { QueryParams, Ranges, Protocol, AcceptsReturns, Middleware } from './types.ts'

Expand Down
2 changes: 1 addition & 1 deletion response.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import type { SendFileOptions } from './extensions/res/send/sendFile.ts'
import type { TemplateEngineOptions, App } from './app.ts'
import type { FormatProps } from './extensions/res/format.ts'
import type { DownloadOptions } from './extensions/res/download.ts'
import { Cookie } from 'https://deno.land/std@0.99.0/http/cookie.ts'
import { Cookie } from 'https://deno.land/std@0.100.0/http/cookie.ts'

export interface Response<O = any> extends ServerResponse, tinyhttp.Response {
headers: Headers
Expand Down
2 changes: 1 addition & 1 deletion tests/core/app.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { App } from '../../app.ts'
import { BindToSuperDeno, InitAppAndTest } from '../util.ts'
import { renderFile as eta } from 'https://deno.land/x/eta@v1.12.2/mod.ts'
import { EtaConfig } from 'https://deno.land/x/eta@v1.12.2/config.ts'
import * as path from 'https://deno.land/std@0.99.0/path/mod.ts'
import * as path from 'https://deno.land/std@0.100.0/path/mod.ts'

describe('App constructor', () => {
it('app.locals are get and set', () => {
Expand Down
2 changes: 1 addition & 1 deletion tests/modules/res.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import {
} from '../../extensions/res/headers.ts'
import { redirect } from '../../extensions/res/redirect.ts'
import { attachment } from '../../extensions/res/download.ts'
import * as path from 'https://deno.land/std@0.99.0/path/mod.ts'
import * as path from 'https://deno.land/std@0.100.0/path/mod.ts'

const __dirname = new URL('.', import.meta.url).pathname

Expand Down
2 changes: 1 addition & 1 deletion utils/parseUrl.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { parse } from 'https://deno.land/std@0.99.0/node/querystring.ts'
import { parse } from 'https://deno.land/std@0.100.0/node/querystring.ts'

type Regex = {
keys: string[] | boolean
Expand Down

0 comments on commit bb680bd

Please sign in to comment.