Skip to content

Commit

Permalink
replace esm.sh with skypack bc it died
Browse files Browse the repository at this point in the history
  • Loading branch information
v1rtl committed Sep 9, 2021
1 parent a4f86c2 commit 6294afa
Show file tree
Hide file tree
Showing 11 changed files with 45 additions and 37 deletions.
6 changes: 5 additions & 1 deletion .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
{
"deno.enable": true
"deno.enable": true,
"deno.suggest.imports.hosts": {
"https://deno.land/x/": true,
"https://x.nest.land/": true
}
}
14 changes: 10 additions & 4 deletions deps.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { default as parseRange, Options } from 'https://esm.sh/range-parser@1.2.1'
import { default as parseRange, Options } from 'https://cdn.skypack.dev/range-parser@1.2.1?dts'
export { parseRange }
export type { Options as ParseRangeOptions }
export { Sha1 } from 'https://deno.land/std@0.106.0/hash/sha1.ts'
Expand All @@ -11,7 +11,7 @@ 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.12/mod.ts'
export * from 'https://deno.land/x/proxy_addr@0.0.19/mod.ts'
import type { ServerRequest as Req, Response as ServerResponse } from 'https://deno.land/std@0.106.0/http/server.ts'
export { default as ipaddr, IPv4, IPv6 } from 'https://cdn.skypack.dev/ipaddr.js'
export { default as ipaddr, IPv4, IPv6 } from 'https://cdn.skypack.dev/ipaddr.js?dts'
interface Res extends ServerResponse {
headers: Headers
}
Expand All @@ -22,5 +22,11 @@ export type { Req, Res }

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

export { Router, pushMiddleware } from 'https://esm.sh/@tinyhttp/router@2.0.0'
export type { NextFunction, Handler, Middleware, UseMethodParams, Method } from 'https://esm.sh/@tinyhttp/router@2.0.0'
export { Router, pushMiddleware } from 'https://cdn.skypack.dev/@tinyhttp/router@2.0.0?dts'
export type {
NextFunction,
Handler,
Middleware,
UseMethodParams,
Method
} from 'https://cdn.skypack.dev/@tinyhttp/router@2.0.0?dts'
2 changes: 1 addition & 1 deletion extensions/res/download.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { contentDisposition } from 'https://cdn.skypack.dev/@tinyhttp/content-disposition@2.0.0'
import { contentDisposition } from 'https://cdn.skypack.dev/@tinyhttp/content-disposition@2'
import { SendFileOptions, sendFile } from './send/sendFile.ts'
import { extname } from 'https://deno.land/std@0.106.0/path/mod.ts'
import { setContentType, setHeader } from './headers.ts'
Expand Down
46 changes: 22 additions & 24 deletions extensions/res/format.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Handler, NextFunction } from 'https://esm.sh/@tinyhttp/router'
import { Handler, NextFunction } from '../../deps.ts'
import { normalizeType, normalizeTypes } from './utils.ts'
import { setVaryHeader } from './headers.ts'
import { getAccepts } from '../req/mod.ts'
Expand All @@ -8,34 +8,32 @@ export type FormatProps = {
default?: () => void
} & Record<string, Handler>

export const formatResponse = <Request extends Req = Req, Response extends Res = Res>(
req: Request,
res: Response,
next: NextFunction
) => (obj: FormatProps) => {
const fn = obj.default
export const formatResponse =
<Request extends Req = Req, Response extends Res = Res>(req: Request, res: Response, next: NextFunction) =>
(obj: FormatProps) => {
const fn = obj.default

if (fn) delete obj.default
if (fn) delete obj.default

const keys = Object.keys(obj)
const keys = Object.keys(obj)

const key = keys.length > 0 ? (getAccepts(req)(...keys) as string) : false
const key = keys.length > 0 ? (getAccepts(req)(...keys) as string) : false

setVaryHeader(res)('Accept')
setVaryHeader(res)('Accept')

if (key) {
res.headers?.set('Content-Type', normalizeType(key).value || '')
if (key) {
res.headers?.set('Content-Type', normalizeType(key).value || '')

obj[key](req, res, next)
} else if (fn) {
fn()
} else {
const err = new Error('Not Acceptable') as any
err.status = err.statusCode = 406
err.types = normalizeTypes(keys).map((o) => o.value)
obj[key](req, res, next)
} else if (fn) {
fn()
} else {
const err = new Error('Not Acceptable') as any
err.status = err.statusCode = 406
err.types = normalizeTypes(keys).map((o) => o.value)

next(err)
}
next(err)
}

return res
}
return res
}
2 changes: 1 addition & 1 deletion tests/core/app.test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { describe, it, expect, run } from 'https://deno.land/x/tincan@0.2.1/mod.ts'
import { describe, it, expect, run } from 'https://deno.land/x/tincan@0.2.2/mod.ts'
import { App } from '../../app.ts'
import { BindToSuperDeno, InitAppAndTest } from '../util.ts'
import { renderFile as eta } from 'https://deno.land/x/eta@v1.12.3/mod.ts'
Expand Down
2 changes: 1 addition & 1 deletion tests/core/request.test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { describe, it, run } from 'https://deno.land/x/tincan@0.2.1/mod.ts'
import { describe, it, run } from 'https://deno.land/x/tincan@0.2.2/mod.ts'
import { App } from '../../app.ts'

import { BindToSuperDeno, InitAppAndTest } from '../util.ts'
Expand Down
2 changes: 1 addition & 1 deletion tests/modules/etag.test.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { etag } from '../../utils/etag.ts'
import { describe, it, expect, run } from 'https://deno.land/x/tincan@0.2.1/mod.ts'
import { describe, it, expect, run } from 'https://deno.land/x/tincan@0.2.2/mod.ts'

describe('etag(body)', function () {
it('should support strings', function () {
Expand Down
2 changes: 1 addition & 1 deletion tests/modules/parseUrl.test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { describe, it, expect, run } from 'https://deno.land/x/tincan@0.2.1/mod.ts'
import { describe, it, expect, run } from 'https://deno.land/x/tincan@0.2.2/mod.ts'
import { getPathname, getQueryParams, getURLParams } from '../../utils/parseUrl.ts'
import { rg } from '../../deps.ts'

Expand Down
2 changes: 1 addition & 1 deletion tests/modules/req.test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { describe, it, expect, run } from 'https://deno.land/x/tincan@0.2.1/mod.ts'
import { describe, it, expect, run } from 'https://deno.land/x/tincan@0.2.2/mod.ts'
import { InitAppAndTest, runServer } from '../util.ts'
import { Ranges } from '../../types.ts'
import {
Expand Down
2 changes: 1 addition & 1 deletion tests/modules/res.test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { describe, it, run, expect } from 'https://deno.land/x/tincan@0.2.1/mod.ts'
import { describe, it, run, expect } from 'https://deno.land/x/tincan@0.2.2/mod.ts'
import { InitAppAndTest, runServer } from '../util.ts'
import {
setHeader,
Expand Down
2 changes: 1 addition & 1 deletion tests/modules/send.test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { describe, it, run, beforeAll, afterAll, expect } from 'https://deno.land/x/tincan@0.2.1/mod.ts'
import { describe, it, run, beforeAll, afterAll, expect } from 'https://deno.land/x/tincan@0.2.2/mod.ts'
import * as path from 'https://deno.land/std@0.106.0/path/mod.ts'
import * as fs from 'https://deno.land/std@0.106.0/node/fs.ts'
import { runServer } from '../util.ts'
Expand Down

0 comments on commit 6294afa

Please sign in to comment.