mirror of
https://github.com/elysiajs/elysia
synced 2026-08-09 12:35:48 +00:00
🔧 fix: use system router
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
# 1.4.22
|
||||
Bug fix:
|
||||
- ValueError with summary missing types
|
||||
- Elysia not using Bun.routes
|
||||
|
||||
# 1.4.21 - 4 Jan 2026
|
||||
Improvement:
|
||||
|
||||
+2
-42
@@ -1,43 +1,3 @@
|
||||
import { Elysia, t } from '../src'
|
||||
import { Elysia } from '../src'
|
||||
|
||||
export const errorHandler = new Elysia({ name: "error-handler" })
|
||||
.onError(({ code, error, status }) => {
|
||||
switch (code) {
|
||||
case "VALIDATION": {
|
||||
const allErrors = error.detail
|
||||
|
||||
return status(422, {
|
||||
status: 422,
|
||||
message: error.valueError?.message,
|
||||
details: {
|
||||
location: error.type,
|
||||
rejected_value: error.value,
|
||||
expected: error.expected,
|
||||
},
|
||||
})
|
||||
}
|
||||
case "NOT_FOUND": {
|
||||
return status(404, {
|
||||
status: 404,
|
||||
message: "Route not found",
|
||||
})
|
||||
}
|
||||
default: {
|
||||
const statusCode =
|
||||
"status" in error
|
||||
? (typeof error.status === "number" ? error.status : Number(error.status)) || 500
|
||||
: 500
|
||||
|
||||
let errMsg = "An error occurred"
|
||||
if (error instanceof Error && error.message) {
|
||||
errMsg = error.message
|
||||
}
|
||||
|
||||
return status(statusCode, {
|
||||
status: statusCode,
|
||||
message: errMsg,
|
||||
})
|
||||
}
|
||||
}
|
||||
})
|
||||
.as("scoped")
|
||||
const app = new Elysia().get('/', () => 'a').listen(3000)
|
||||
|
||||
@@ -84,7 +84,7 @@ const supportedMethods = {
|
||||
} as const
|
||||
|
||||
const mapRoutes = (app: AnyElysia) => {
|
||||
if (!app.config.aot || !app.config.systemRouter) return undefined
|
||||
if (!app.config.aot || app.config.systemRouter === false) return undefined
|
||||
|
||||
const routes = <Record<string, Function | Record<string, unknown>>>{}
|
||||
|
||||
|
||||
@@ -136,7 +136,7 @@ export const responseToSetHeaders = (
|
||||
return set
|
||||
}
|
||||
|
||||
type CreateHandlerParameter = {
|
||||
interface CreateHandlerParameter {
|
||||
mapResponse(
|
||||
response: unknown,
|
||||
set: Context['set'],
|
||||
|
||||
@@ -3,7 +3,6 @@ import { AnyElysia, Cookie } from './index'
|
||||
import { Value, TransformDecodeError } from '@sinclair/typebox/value'
|
||||
import {
|
||||
Kind,
|
||||
OptionalKind,
|
||||
TypeBoxError,
|
||||
type TAnySchema,
|
||||
type TSchema
|
||||
@@ -372,11 +371,9 @@ const matchFnReturn = /(?:return|=>)\s?\S+\(|a(?:sync|wait)/
|
||||
|
||||
export const isAsync = (v: Function | HookContainer) => {
|
||||
const isObject = typeof v === 'object'
|
||||
|
||||
if (isObject && v.isAsync !== undefined) return v.isAsync
|
||||
|
||||
const fn = isObject ? v.fn : v
|
||||
|
||||
if (fn.constructor.name === 'AsyncFunction') return true
|
||||
|
||||
const literal: string = fn.toString()
|
||||
@@ -388,7 +385,6 @@ export const isAsync = (v: Function | HookContainer) => {
|
||||
}
|
||||
|
||||
const result = matchFnReturn.test(literal)
|
||||
|
||||
if (isObject) v.isAsync = result
|
||||
|
||||
return result
|
||||
|
||||
@@ -145,6 +145,8 @@ export const fileType = async (
|
||||
const result = await fileTypeFromBlob(file)
|
||||
if (!result) throw new InvalidFileType(name, extension)
|
||||
|
||||
console.log(result, extension)
|
||||
|
||||
if (typeof extension === 'string')
|
||||
if (!checkFileExtension(result.mime, extension))
|
||||
throw new InvalidFileType(name, extension)
|
||||
|
||||
Reference in New Issue
Block a user