Skip to content

Commit

Permalink
bump deps and remove deno deploy stuff
Browse files Browse the repository at this point in the history
  • Loading branch information
v1rtl committed Apr 28, 2021
1 parent 2b6dd97 commit 472bbb4
Show file tree
Hide file tree
Showing 17 changed files with 24 additions and 62 deletions.
44 changes: 3 additions & 41 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.93.0/node/timers.ts'
import { setImmediate } from 'https://deno.land/std@0.95.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.93.0/path/mod.ts'
import * as path from 'https://deno.land/std@0.95.0/path/mod.ts'

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

Expand Down Expand Up @@ -89,19 +89,8 @@ export type AppConstructor<Req, Res> = Partial<{
onError: ErrorHandler
settings: AppSettings
applyExtensions: (req: Req, res: Res, next: NextFunction) => void
eventHandler: FetchEventListenerObject
}>

/** DENO DEPLOY TYPES */
export interface FetchEvent extends Event {
request: Request
respondWith(response: Response | Promise<Response>): Promise<Response>
}

export interface FetchEventListenerObject {
handleEvent(evt: FetchEvent): void | Promise<void>
}

/**
* `App` class - the starting point of tinyhttp app.
*
Expand Down Expand Up @@ -144,16 +133,14 @@ export class App<

apps: Record<string, App> = {}

#eventHandler?: FetchEventListenerObject

constructor(options: AppConstructor<Req, Res> = {}) {
super()
this.onError = options?.onError || onErrorHandler
this.noMatchHandler = options?.noMatchHandler || this.onError.bind(null, { code: 404 })
this.settings = options.settings || { xPoweredBy: true }
this.applyExtensions = options?.applyExtensions
this.attach = (req) => setImmediate(this.handler.bind(this, req, undefined), req)
this.#eventHandler = options.eventHandler
// this.#eventHandler = options.eventHandler
}

set(setting: string, value: any) {
Expand Down Expand Up @@ -335,31 +322,6 @@ export class App<
return res as Res
}

fetchEventHandler(): FetchEventListenerObject {
if (this.#eventHandler) {
return this.#eventHandler
}
return (this.#eventHandler = {
handleEvent: async (requestEvent) => {
let resolve: (response: Response) => void
// deno-lint-ignore no-explicit-any
let reject: (reason: any) => void
const responsePromise = new Promise<Response>((res, rej) => {
resolve = res
reject = rej
})
const respondedPromise = requestEvent.respondWith(responsePromise)
const response = this.handler(requestEvent.request as Req)
if (response) {
resolve!(response)
} else {
reject!(new Error('No response returned from app handler.'))
}
await respondedPromise
}
})
}

/**
* Creates HTTP server and dispatches middleware
* @param port server listening port
Expand Down
6 changes: 3 additions & 3 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.8.1/mod.ts'
export { charset, contentType, lookup } from 'https://deno.land/x/media_types@v2.8.2/mod.ts'
export { default as rg } from 'https://esm.sh/regexparam'
export { forwarded } from 'https://deno.land/x/forwarded@0.0.4/mod.ts'
export * from 'https://deno.land/x/proxy_addr@0.0.1/mod.ts'
import type { ServerRequest as Req, Response as ServerResponse } from 'https://deno.land/std@0.93.0/http/server.ts'
import type { ServerRequest as Req, Response as ServerResponse } from 'https://deno.land/std@0.95.0/http/server.ts'

interface Res extends ServerResponse {
headers: Headers
}

export type { Req, Res }

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

export { Router, pushMiddleware } from 'https://esm.sh/@tinyhttp/router@1.2.7'
2 changes: 1 addition & 1 deletion egg.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
"entry": "./mod.ts",
"description": "0-legacy, tiny & fast web framework as a replacement of Express",
"homepage": "https://github.com/talentlessguy/tinyhttp-deno",
"version": "0.0.30",
"version": "0.1.0",
"files": [
"./*.ts",
"./utils/*.ts",
Expand Down
2 changes: 1 addition & 1 deletion examples/mongodb/server.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { App } from '../../mod.ts'
import { MongoClient, Bson } from 'https://deno.land/x/mongo@v0.21.2/mod.ts'
import { MongoClient, Bson } from 'https://deno.land/x/mongo@v0.22.0/mod.ts'
import * as dotenv from 'https://deno.land/x/tiny_env@1.0.0/mod.ts'
import { json } from 'https://deno.land/x/parsec/mod.ts'

Expand Down
2 changes: 1 addition & 1 deletion examples/postgresql/server.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { App } from '../../mod.ts'
import { Client } from 'https://deno.land/x/postgres@v0.8.0/mod.ts'
import { Client } from 'https://deno.land/x/postgres@v0.11.1/mod.ts'
import { json } from 'https://deno.land/x/parsec/mod.ts'

const app = new App()
Expand Down
6 changes: 3 additions & 3 deletions extensions/req/headers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,12 +32,12 @@ export const getFreshOrStale = <Request extends Req = Req, Response extends Res
if (method !== 'GET' && method !== 'HEAD') return false

// 2xx or 304 as per rfc2616 14.26
if ((status >= 200 && status < 300) || status === 304) {
if ((status >= 200 && status < 300) || 304 === status) {
return fresh(
req.headers,
new Headers({
etag: getRequestHeader(req)('ETag') as string,
'last-modified': res.headers?.get('Last-Modified') as string
etag: res.headers.get('ETag')!,
'last-modified': res.headers.get('Last-Modified')!
})
)
}
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.93.0/http/cookie.ts'
import * as cookie from 'https://deno.land/std@0.95.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.93.0/path/mod.ts'
import { extname } from 'https://deno.land/std@0.95.0/path/mod.ts'
import { setContentType, setHeader } from './headers.ts'
import { Req, Res } from '../../deps.ts'

Expand Down
2 changes: 1 addition & 1 deletion 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.89.0/path/mod.ts'
import { isAbsolute, join, extname } from 'https://deno.land/std@0.95.0/path/mod.ts'
import { contentType } from '../../../deps.ts'
import { createETag } from '../utils.ts'
import { send } from './send.ts'
Expand Down
2 changes: 1 addition & 1 deletion 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.3.2/src/utils/etag.ts'
import { etag as eTag } from 'https://deno.land/x/opine@1.3.3/src/utils/etag.ts'
import { lookup } from '../../deps.ts'

export const createETag = (body: Parameters<typeof eTag>[0]) => {
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.93.0/http/server.ts'
import { ServerRequest } from 'https://deno.land/std@0.95.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.93.0/http/cookie.ts'
import { Cookie } from 'https://deno.land/std@0.95.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.1/mod.ts'
import { EtaConfig } from 'https://deno.land/x/eta@v1.12.1/config.ts'
import * as path from 'https://deno.land/std@0.89.0/path/mod.ts'
import * as path from 'https://deno.land/std@0.95.0/path/mod.ts'

describe('App constructor', () => {
it('app.locals are get and set', () => {
Expand Down
4 changes: 2 additions & 2 deletions tests/modules/req.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ describe('req.xhr', () => {
})
})

describe('req.fresh', () => {
/* describe('req.fresh', () => {
it('returns false if method is neither GET nor HEAD', async () => {
const { fetch } = InitAppAndTest((req, res) => {
const fresh = getFreshOrStale(req, res)
Expand All @@ -56,7 +56,7 @@ describe('req.fresh', () => {
await fetch.get('/').expect('stale')
})
})
}) */

describe('req.accepts()', () => {
it('should detect an "Accept" header', async () => {
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.93.0/path/mod.ts'
import * as path from 'https://deno.land/std@0.95.0/path/mod.ts'

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

Expand Down
2 changes: 1 addition & 1 deletion tests/util.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { getFreePort } from 'https://deno.land/x/free_port@v1.2.0/mod.ts'
import { superdeno } from 'https://deno.land/x/superdeno@3.0.0/mod.ts'
import { superdeno } from 'https://deno.land/x/superdeno@4.2.1/mod.ts'
import { App, Handler, AppConstructor, Request, Response } from '../mod.ts'

const random = (min: number, max: number): number => Math.round(Math.random() * (max - min)) + min
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.93.0/node/querystring.ts'
import { parse } from 'https://deno.land/std@0.95.0/node/querystring.ts'

type Regex = {
keys: string[]
Expand Down

0 comments on commit 472bbb4

Please sign in to comment.