import { headers } from "next/headers";
import { NextResponse } from "next/server";
export const GET = async (request: Request) => {
const apiHeaders = {
"Content-Type": "application/json",
"x-api-key": "<Replace-your-octolane-api-key>",
};
const headersList = headers();
/**
* You will not see any ip address while working on localhost.
* You will need to deploy your app to see the ip address. But, alternatively you can use a
* dummy ip address for testing purpose.
*/
const ip = headersList.get("x-forwarded-for");
if (!ip) {
return NextResponse.json({
success: false,
statusCode: 400,
message: "IP address is not found",
});
}
try {
const response = await fetch(
`https://enrich.octolane.com/v1/ip-to-company?ip=${ip}`,
{
method: "GET",
headers: apiHeaders,
},
);
const data = await response.json();
return NextResponse.json({
success: true,
statusCode: 200,
data: data.data,
});
} catch (error) {
return NextResponse.json({
success: false,
statusCode: 404,
message: "Couldn't identified company",
});
}
};