my problem with ssr in angular version 17
iam using proxy.config.json to handle CORS error in app
but ssr server.ts file can’t deal with this proxy config in development and result for this all http request its response is html code instead of json response;
So My question is :
How to Make SSR deal proxy config??
Note : i upgrade my angular from version 16 to 17 and convert it from Module to standalone app ;
Thanks in Advance.
i add this part of code to server.ts file ????????????
if (!environment.production) {
const proxyOptions: any = {
target:
'https://tmg-ksa-admin-dev.nuca-mycluster-eu-de-1-cx-5fc3035946e1f798c7284cb63267e8d1-0000.eu-de.containers.appdomain.cloud/',
secure: true,
changeOrigin: true,
logLevel: 'debug',
timeout: 600000,
pathRewrite: {
'^/local': '',
},
onProxyReq: (
proxyReq: ClientRequest,
req: IncomingMessage,
res: ServerResponse
) => {
console.log('Proxying request:', req.method, req.url);
},
onProxyRes: (
proxyRes: IncomingMessage,
req: IncomingMessage,
res: ServerResponse
) => {
let body: Buffer[] = [];
proxyRes.on('data', (chunk: Buffer) => {
body.push(chunk);
});
proxyRes.on('end', () => {
const responseBody = Buffer.concat(body).toString();
console.log('Received response:', proxyRes.statusCode, responseBody);
});
},
};
server.use('/local', createProxyMiddleware(proxyOptions));
}
it work when i run this commands :
npm run watch
npm run serve:ssr:project-name
when i run normal server : ng s -o
it doesn’t work
ahmed mostfa is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.