Skip to content

Commit

Permalink
tmp: add test proxy
Browse files Browse the repository at this point in the history
  • Loading branch information
weaigc committed Aug 19, 2023
1 parent d2c97db commit 3113f5d
Showing 1 changed file with 20 additions and 0 deletions.
20 changes: 20 additions & 0 deletions src/pages/api/proxy.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
'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 })
.then((res) => res.text())

res.end(response)
} catch (e) {
console.log(e)
return res.end(e)
}
}

0 comments on commit 3113f5d

Please sign in to comment.