File size: 664 Bytes
f0836f1
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
'use server'

import { NextApiRequest, NextApiResponse } from 'next'
import { fetch } from '@/lib/isomorphic'

export default async function handler(req: NextApiRequest, res: NextApiResponse) {
  try {
    const { url, headers, method = 'GET', body } = req.body
    if (!url) {
      return res.end('ok')
    }
    const response = await fetch(url, { headers, method, body, redirect: 'manual' })
    const text = await response.text()
      res.writeHead(200, {
        'Content-Type': 'application/text',
        'x-url': response.url,
        'x-status': response.status,
      })
    res.end(text)
  } catch (e) {
    console.log(e)
    return res.end(e)
  }
}