bingo / src /pages /api /create.ts
nier111's picture
Duplicate from hf4all/bingo
fbad01d
raw
history blame contribute delete
No virus
853 Bytes
'use server'
import { NextApiRequest, NextApiResponse } from 'next'
import { fetch, debug } from '@/lib/isomorphic'
import { createHeaders } from '@/lib/utils'
// const API_ENDPOINT = 'https://www.bing.com/turing/conversation/create'
const API_ENDPOINT = 'https://edgeservices.bing.com/edgesvc/turing/conversation/create';
export default async function handler(req: NextApiRequest, res: NextApiResponse) {
try {
const headers = createHeaders(req.cookies)
res.writeHead(200, {
'Content-Type': 'application/json',
})
debug('headers', headers)
const response = await fetch(API_ENDPOINT, { method: 'GET', headers })
.then((res) => res.text())
res.end(response)
} catch (e) {
return res.end(JSON.stringify({
result: {
value: 'UnauthorizedRequest',
message: `${e}`
}
}))
}
}