Team Ai
Apppublic

code2024/bingo

sourceHugging Facemitupdated 3y agoView on Hugging Face
0likes
create.ts32 linesDownload Raw Back to api
1'use server'2 3import { NextApiRequest, NextApiResponse } from 'next'4import { fetch, debug } from '@/lib/isomorphic'5import { createHeaders } from '@/lib/utils'6 7const API_ENDPOINT = 'https://www.bing.com/turing/conversation/create'8// const API_ENDPOINT = 'https://edgeservices.bing.com/edgesvc/turing/conversation/create';9 10export default async function handler(req: NextApiRequest, res: NextApiResponse) {11  try {12    const headers = createHeaders(req.cookies)13 14    res.writeHead(200, {15      'Content-Type': 'application/json',16    })17 18    debug('headers', headers)19    const response = await fetch(API_ENDPOINT, { method: 'GET', headers })20      .then((res) => res.text())21 22    res.end(response)23  } catch (e) {24    return res.end(JSON.stringify({25      result: {26        value: 'UnauthorizedRequest',27        message: `${e}`28      }29    }))30  }31}32