The error message you're encountering indicates a CORS (Cross-Origin Resource Sharing) issue. This occurs when a web application at one origin (in this case, https://prmira.ru) tries to access resources hosted on another origin (the image URL you provided), and the server hosting the resource does not permit this.
To fix this issue, you need to ensure that the server hosting the image is set up to allow requests from your origin. Here’s how to resolve or work around the issue:
1. Server-Side Solution
You'll need to update the server that hosts the image to allow requests from your domain. Specifically, you need to configure the server to return the Access-Control-Allow-Origin header with a valid value. Here's how to do that for different types of servers:
For Apache:
Add the following lines to your .htaccess file or your Apache configuration:
<IfModule mod_headers.c>
Header set Access-Control-Allow-Origin "https://prmira.ru"
</IfModule>
For Nginx:
Add the following line to the server block in your Nginx configuration:
add_header 'Access-Control-Allow-Origin' 'https://prmira.ru';
For Express.js (Node.js):
In an Express application, use the following middleware:
const cors = require('cors');
app.use(cors({ origin: 'https://prmira.ru' }));
2. Using a Proxy
If you do not have control over the server that hosts the image, you could set up a proxy on your server. Your application can make requests to your own server, and your server can then fetch the image and return it to your application. This way, CORS issues are avoided. Here’s a simple example using Express:
const express = require('express');
const request = require('request');
const app = express();
app.get('/proxy/image', (req, res) => {
const imageUrl = 'https://cdn.1mi.media/cf04cf4...'; // Original image URL
request(imageUrl).pipe(res);
});
app.listen(3000, () => {
console.log('Proxy server running on port 3000');
});
3. Debugging CORS Issues
Ensure that:
- The URL for which CORS headers are being set is correct.
- The value of
Access-Control-Allow-Origin is the exact origin requesting it or * to allow all origins (not recommended for sensitive content).
- If the image requires authentication or specific headers, make sure to also include those in the request.
4. Test Without CORS (For Development Only)
For local development and testing purposes, you can disable web security in Chrome (not recommended for production or regular use):
chrome.exe --user-data-dir="C:/Chrome dev session" --disable-web-security
Conclusion
While you can use the methods above to bypass or fix CORS-related issues, the best approach is to properly configure the server where the resource is hosted. If you control the server, update the CORS settings accordingly. If not, consider using a proxy or providing access on the server side.