Я пытаюсь создать работника CloudFlare, используя itty-router. Следуя руководству по TypeScript, мы должны определить типы TypeScript, как в коде ниже.Argument of type '({ content }: IRequest, env: Args[0], ctx: Args[1]) => Promise' is not assignable to parameter of type 'RequestHandler'.
Target signature provides too few arguments. Expected 3 or more, but got 1.ts(2345)
< /code>
import { createClient } from '@supabase/supabase-js'
import { AutoRouter, RequestHandler, IRequest, withContent } from 'itty-router'
interface Env {
SUPABASE_URL: string
SUPABASE_KEY: string
}
type CFArgs = [Env, ExecutionContext]
const router = AutoRouter()
router.post(
'/clients',
withContent,
// async (request: RequestHandler) => {
// async ({ content }: IRequest, env: Env, ctx: ExecutionContext) => {
// async ({ content }, env, ctx) => {
async ({ content }, env, ctx) => {
try {
const body = content as { [key: string]: any }
if (!body || Object.keys(body).length === 0) {
throw new Error('Invalid request body: Empty or undefined')
}
const newClient = { ...body }
const supabase = createClient(env.SUPABASE_URL, env.SUPABASE_KEY)
const { data, error } = await supabase.from('clients').insert(newClient)
if (error) throw new Error(`Supabase error: ${error.message}`)
return {
success: true,
status: 200,
data: newClient,
error: null,
}
} catch (error: any) {
return { success: false, status: 500, data: null, error: error.message }
}
}
)
Подробнее здесь: https://stackoverflow.com/questions/796 ... middleware
Itty-Router и TypeScript с промежуточным программным обеспечением ⇐ Javascript
Форум по Javascript
-
Anonymous
1746360362
Anonymous
Я пытаюсь создать работника CloudFlare, используя itty-router. Следуя руководству по TypeScript, мы должны определить типы TypeScript, как в коде ниже.Argument of type '({ content }: IRequest, env: Args[0], ctx: Args[1]) => Promise' is not assignable to parameter of type 'RequestHandler'.
Target signature provides too few arguments. Expected 3 or more, but got 1.ts(2345)
< /code>
import { createClient } from '@supabase/supabase-js'
import { AutoRouter, RequestHandler, IRequest, withContent } from 'itty-router'
interface Env {
SUPABASE_URL: string
SUPABASE_KEY: string
}
type CFArgs = [Env, ExecutionContext]
const router = AutoRouter()
router.post(
'/clients',
withContent,
// async (request: RequestHandler) => {
// async ({ content }: IRequest, env: Env, ctx: ExecutionContext) => {
// async ({ content }, env, ctx) => {
async ({ content }, env, ctx) => {
try {
const body = content as { [key: string]: any }
if (!body || Object.keys(body).length === 0) {
throw new Error('Invalid request body: Empty or undefined')
}
const newClient = { ...body }
const supabase = createClient(env.SUPABASE_URL, env.SUPABASE_KEY)
const { data, error } = await supabase.from('clients').insert(newClient)
if (error) throw new Error(`Supabase error: ${error.message}`)
return {
success: true,
status: 200,
data: newClient,
error: null,
}
} catch (error: any) {
return { success: false, status: 500, data: null, error: error.message }
}
}
)
Подробнее здесь: [url]https://stackoverflow.com/questions/79605582/itty-router-and-typescript-with-middleware[/url]
Ответить
1 сообщение
• Страница 1 из 1
Перейти
- Кемерово-IT
- ↳ Javascript
- ↳ C#
- ↳ JAVA
- ↳ Elasticsearch aggregation
- ↳ Python
- ↳ Php
- ↳ Android
- ↳ Html
- ↳ Jquery
- ↳ C++
- ↳ IOS
- ↳ CSS
- ↳ Excel
- ↳ Linux
- ↳ Apache
- ↳ MySql
- Детский мир
- Для души
- ↳ Музыкальные инструменты даром
- ↳ Печатная продукция даром
- Внешняя красота и здоровье
- ↳ Одежда и обувь для взрослых даром
- ↳ Товары для здоровья
- ↳ Физкультура и спорт
- Техника - даром!
- ↳ Автомобилистам
- ↳ Компьютерная техника
- ↳ Плиты: газовые и электрические
- ↳ Холодильники
- ↳ Стиральные машины
- ↳ Телевизоры
- ↳ Телефоны, смартфоны, плашеты
- ↳ Швейные машинки
- ↳ Прочая электроника и техника
- ↳ Фототехника
- Ремонт и интерьер
- ↳ Стройматериалы, инструмент
- ↳ Мебель и предметы интерьера даром
- ↳ Cантехника
- Другие темы
- ↳ Разное даром
- ↳ Давай меняться!
- ↳ Отдам\возьму за копеечку
- ↳ Работа и подработка в Кемерове
- ↳ Давай с тобой поговорим...
Мобильная версия