I have a website built on next.js but when i test on
localhost:3000/login`. when input the id and password I am forward the proxy using this
http://localhost:3000/api/proxy/?service=auth&endpoint=api/v1/auth/token
my proxy will be directed to others API call to our third-party API
i can login. and i can get the response from others idm integration
but when I am deploying on my server running on ec2. using www.xxxx/login and call http://localhost:3000/api/proxy/?service=auth&endpoint=api/v1/auth/token
my proxy cannot redirect and cannot call our third-party API idm
here is my proxy.ts code
import { NextApiRequest, NextApiResponse } from 'next';
import axios from 'axios';
export default async function handler(req: NextApiRequest, res: NextApiResponse) {
const { endpoint, service } = req.query;
const serviceBaseURLs: Record<string, string> = {
auth: process.env.XYXS_API_URL || '',
otherServices: process.env.ABCD_API_URL || 'http://abcd:9020',
};
const baseURL = serviceBaseURLs[service as string];
const clientId = process.env.PUBLIC_CLIENT_ID || 'ppoc';
const clientSecret = process.env.PUBLIC_CLIENT_SECRET || 'ppocjbndel';
const authorization = 'Basic ' + Buffer.from(`${clientId}:${clientSecret}`).toString('base64');
try {
const response = await axios({
method: req.method,
url: `${baseURL}/${endpoint}`,
headers: {
Authorization: authorization,
'Content-Type': req.headers['content-type'] || 'application/json',
},
data: req.body,
});
res.status(response.status).json(response.data);
} catch (error: any) {
res.status(error.response?.status || 500).json({ error: error.message });
}
}
How do I fix the issue on my ec2 process? I expected that my proxy call on ec2 can be redirected to my third-party API