CoolFace
Apppublic

Sakky1/bingo

sourceHugging Facemitupdated 3y agoView on Hugging Face
0likes
proxy.ts25 linesDownload Raw Back to api
1'use server'2 3import { NextApiRequest, NextApiResponse } from 'next'4import { fetch } from '@/lib/isomorphic'5 6export default async function handler(req: NextApiRequest, res: NextApiResponse) {7  try {8    const { url, headers, method = 'GET', body } = req.body9    if (!url) {10      return res.end('ok')11    }12    const response = await fetch(url, { headers, method, body, redirect: 'manual' })13    const text = await response.text()14      res.writeHead(200, {15        'Content-Type': 'application/text',16        'x-url': response.url,17        'x-status': response.status,18      })19    res.end(text)20  } catch (e) {21    console.log(e)22    return res.end(e)23  }24}25