refactor(serve-static): use context/next instead of MiddlewareHandler (#559)
Before adoption: this commit came in with the history the project adopted, so no landing records it.
* fix(validator): make `isOptional` rule works correctly. * refactor(serve-static): remove return type * use context/next instead of MiddlewareHandler
authored by Yusuke Wada · committed by GitHub · parent c0d88ff · Browse files · 5 files·+20 added−15 removed
This commit
State
Before adoption: this commit came in with the history the project adopted, so no landing records it.
Diff stats
5 files+20 added−15 removed
- other:+20 added−15 removed
Provenance
- Commit
03fc36f- Tree
14382b4- Author
Yusuke Wada <yusuke@kamawada.com>- Committer
GitHub <noreply@github.com>- Parent
c0d88ff
5 files changed+20 added−15 removed
modified:deno_dist/deno/serve-static.ts+4 added-3 removed
11234562 unmodified lines9101112121313141516171834 unmodified linesimport type { MiddlewareHandler } from '../hono.ts'import type { Context } from '../context.ts'import type { Next } from '../hono.ts'import { getFilePath } from '../utils/filepath.ts'import { getMimeType } from '../utils/mime.ts'
export type ServeStaticOptions = {2 unmodified lines}
const DEFAULT_DOCUMENT = 'index.html'
export const serveStatic = (options: ServeStaticOptions = { root: '' }): MiddlewareHandler => { return async (c, next): Promise<Response | undefined> => {export const serveStatic = (options: ServeStaticOptions = { root: '' }) => { return async (c: Context, next: Next) => { // Do nothing if Response is already set if (c.finalized) { await next() }34 unmodified linesmodified:deno_dist/middleware/serve-static/serve-static.ts+4 added-3 removed
11234566 unmodified lines13141516161717181920212227 unmodified linesimport type { MiddlewareHandler } from '../../hono.ts'import type { Context } from '../../context.ts'import type { Next } from '../../hono.ts'import { getContentFromKVAsset } from '../../utils/cloudflare.ts'import { getFilePath } from '../../utils/filepath.ts'import { getMimeType } from '../../utils/mime.ts'
6 unmodified lines
const DEFAULT_DOCUMENT = 'index.html'
// This middleware is available only on Cloudflare Workers.export const serveStatic = (options: ServeStaticOptions = { root: '' }): MiddlewareHandler => { return async (c, next): Promise<Response | undefined> => {export const serveStatic = (options: ServeStaticOptions = { root: '' }) => { return async (c: Context, next: Next) => { // Do nothing if Response is already set if (c.finalized) { await next() }27 unmodified linesmodified:src/deno/serve-static.ts+4 added-3 removed
11234562 unmodified lines9101112121313141516171834 unmodified linesimport type { MiddlewareHandler } from '../hono'import type { Context } from '../context'import type { Next } from '../hono'import { getFilePath } from '../utils/filepath'import { getMimeType } from '../utils/mime'
export type ServeStaticOptions = {2 unmodified lines}
const DEFAULT_DOCUMENT = 'index.html'
export const serveStatic = (options: ServeStaticOptions = { root: '' }): MiddlewareHandler => { return async (c, next): Promise<Response | undefined> => {export const serveStatic = (options: ServeStaticOptions = { root: '' }) => { return async (c: Context, next: Next) => { // Do nothing if Response is already set if (c.finalized) { await next() }34 unmodified linesmodified:src/middleware/serve-static/bun.ts+4 added-3 removed
1 // @denoify-ignore2 /* eslint-disable @typescript-eslint/ban-ts-comment */3 import { existsSync } from 'fs'4-import type { MiddlewareHandler } from '../../hono'4+import type { Context } from '../../context'5+import type { Next } from '../../hono'6 import { getFilePath } from '../../utils/filepath'7 import { getMimeType } from '../../utils/mime'8 9 // @ts-ignore5 unmodified lines15 }16 17 const DEFAULT_DOCUMENT = 'index.html'18 18-export const serveStatic = (options: ServeStaticOptions = { root: '' }): MiddlewareHandler => {19- return async (c, next): Promise<Response | undefined> => {19+export const serveStatic = (options: ServeStaticOptions = { root: '' }) => {20+ return async (c: Context, next: Next) => {21 // Do nothing if Response is already set22 if (c.res && c.finalized) {23 await next()24 }26 unmodified linesmodified:src/middleware/serve-static/serve-static.ts+4 added-3 removed
1-import type { MiddlewareHandler } from '../../hono'1+import type { Context } from '../../context'2+import type { Next } from '../../hono'3 import { getContentFromKVAsset } from '../../utils/cloudflare'4 import { getFilePath } from '../../utils/filepath'5 import { getMimeType } from '../../utils/mime'6 6 unmodified lines13 14 const DEFAULT_DOCUMENT = 'index.html'15 16 // This middleware is available only on Cloudflare Workers.16-export const serveStatic = (options: ServeStaticOptions = { root: '' }): MiddlewareHandler => {17- return async (c, next): Promise<Response | undefined> => {17+export const serveStatic = (options: ServeStaticOptions = { root: '' }) => {18+ return async (c: Context, next: Next) => {19 // Do nothing if Response is already set20 if (c.finalized) {21 await next()22 }27 unmodified lines