CoolFace
Apppublic

miniocean404/bingo

sourceHugging Facemitupdated 3y agoView on Hugging Face
0likes
create.ts33 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.setHeader('set-cookie', headers.cookie)15    res.writeHead(200, {16      'Content-Type': 'application/json',17    })18 19    debug('headers', headers)20    const response = await fetch(API_ENDPOINT, { method: 'GET', headers })21      .then((res) => res.text())22 23    res.end(response)24  } catch (e) {25    return res.end(JSON.stringify({26      result: {27        value: 'UnauthorizedRequest',28        message: `${e}`29      }30    }))31  }32}33