#About Integrate biometric device in angular
26 messages · Page 1 of 1 (latest)
I have to integrate mfs biometric device rd service but getting cors error in production but locally working how to fix this error..
captureData(): Observable<any> {
if (this.captureUrl !== '') {
let doc = document.implementation.createDocument("", "", null);
let pidOptionsElem = doc.createElement("PidOptions");
let optsElem = doc.createElement("Opts");
optsElem.setAttribute("fCount", '1');
optsElem.setAttribute("fType", '2');
optsElem.setAttribute("iCount", '0');
optsElem.setAttribute("pCount", '0');
optsElem.setAttribute("format", '0');
optsElem.setAttribute("pidVer", "2.0");
optsElem.setAttribute("timeout", '10000');
optsElem.setAttribute("posh", "UNKNOWN");
optsElem.setAttribute("env", "P");
pidOptionsElem.appendChild(optsElem);
doc.appendChild(pidOptionsElem);
const headers = new HttpHeaders({
'Content-Type': 'application/xml',
'Accept': 'application/xml'
});
return this.customRequest('CAPTURE', this.captureUrl, new XMLSerializer().serializeToString(doc), headers).pipe(
map(response => {
let parser = new DOMParser();
let xml = parser.parseFromString(response as string, "application/xml");
var xmlText = new XMLSerializer().serializeToString(xml);
let resp = xml.querySelector("Resp");
let errCode = resp?.getAttribute('errCode');
let errInfo = resp?.getAttribute('errInfo');
let qScore = resp?.getAttribute('qScore');
return {
status: errCode === '0' ? 1 : 2,
message: errCode === '0' ? `Capture Success: Quality - ${qScore}` : `Capture Failed: ${errInfo}`,
captureSuccess: errCode === '0',
pidData: xmlText
};
}),
catchError(() => of({ status: 2, message: 'Capture failed' }))
);
} else {
return of({ status: 2, message: 'Device is not ready for capture!' });
}
}
Ok @abstract field
If you're getting CORS errors, the server (at this.captureUrl) needs to properly set CORS headers.
CORS errors need to be resolved on your backend, you need to configure it to be able to receive requests from the domain your frontend is on
{
"http://127.0.0.1:11101/": {
"target": "http://127.0.0.1:11101",
"secure": false,
"changeOrigin": true,
"logLevel": "debug",
"pathRewrite": {
"^/api": ""
}
}
}
this is my proxy.conf.js file is it correct or not?
proxy only works locally in development, for production you need to configure your backend
can you elaborate with example which header pass for fixing cors error?
You don't need a header, you need to configure some middleware for your server that allows/disallows requests. What backend are you using (e.g. express, .net, etc)?
Your backend needs to send the proper CORS headers.
You can learn about CORS on MDN: https://developer.mozilla.org/en-US/docs/Web/HTTP/CORS.
In the most basic setup the server only needs to send the Access-Control-Allow-Origin header and handle the CORS preflight. However as Michael said, there is probably a ready-made middleware for whatever backend you are using.
I am using php ci4 for backend
Ok, follow the link that diesieben07 posted and it should explain you how to set it up
already set headers at backend because other api works properly..
but using biometric device I have to integrate aeps
If your frontend is making a request directly to that "biometric device" then that device needs to send the CORS headers.
yes this is actual..
then how to send the cors header..?
You have to look in the documentation for that device.
In this document not getting any idea about cors error how to fix it?
not getting in this document of above attached..
how to fix it?
Look at the network tab in your browser devtools when the request happens. Does the device send proper CORS headers back?
I also see zero API documentation in the documents you linked
Is that the preflight request?
yes