2022-05-17 04:02:14 +02:00
|
|
|
import axios from 'axios';
|
2022-11-19 11:45:02 +00:00
|
|
|
import https from 'https';
|
2022-05-17 04:02:14 +02:00
|
|
|
import { NextApiRequest, NextApiResponse } from 'next';
|
|
|
|
|
|
|
|
|
|
async function Get(req: NextApiRequest, res: NextApiResponse) {
|
|
|
|
|
// Parse req.body as a ServiceItem
|
|
|
|
|
const { url } = req.query;
|
2022-11-19 11:45:02 +00:00
|
|
|
const agent = new https.Agent({ rejectUnauthorized: false });
|
2022-05-17 04:02:14 +02:00
|
|
|
await axios
|
2022-11-19 11:45:02 +00:00
|
|
|
.get(url as string, { httpsAgent: agent })
|
2022-05-17 04:02:14 +02:00
|
|
|
.then((response) => {
|
2022-06-16 15:38:50 -04:00
|
|
|
res.status(response.status).json(response.statusText);
|
2022-05-17 04:02:14 +02:00
|
|
|
})
|
|
|
|
|
.catch((error) => {
|
2022-06-20 09:52:05 +02:00
|
|
|
if (error.response) {
|
|
|
|
|
res.status(error.response.status).json(error.response.statusText);
|
|
|
|
|
} else {
|
|
|
|
|
res.status(500).json('Server Error');
|
|
|
|
|
}
|
2022-05-17 04:02:14 +02:00
|
|
|
});
|
|
|
|
|
// // Make a request to the URL
|
|
|
|
|
// const response = await axios.get(url);
|
|
|
|
|
// // Return the response
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export default async (req: NextApiRequest, res: NextApiResponse) => {
|
|
|
|
|
// Filter out if the reuqest is a POST or a GET
|
|
|
|
|
if (req.method === 'GET') {
|
|
|
|
|
return Get(req, res);
|
|
|
|
|
}
|
|
|
|
|
return res.status(405).json({
|
|
|
|
|
statusCode: 405,
|
|
|
|
|
message: 'Method not allowed',
|
|
|
|
|
});
|
|
|
|
|
};
|