I have an express server that allows the front end to get information from the database it works fine. Cors is set up with the front end whitelisted but, trying to get an image (that has already been uploaded and saved) comes back with nothing except a 500 error. I tried disabling cors and it worked fine but any origin can do things which is not what I wanted for this website. Im using apache with the proxy and proxy_http mod enabled so it can access the express js server running on pm2. code on server js:
const whiteList=['domain.com'];
const corsOptions = {
origin:function(origin, callback){
if(whiteList.indexOf(origin) !== -1){
callback(null, true);
} else{
callback(new Error('Not allowed by CORS'));
}
}
}
app.use(cors(corsOptions));
I have even tried setting up cors headers in apache but it doesn't work as it still lets in origins not listes.