【发布时间】:2017-10-16 21:14:20
【问题描述】:
我有一个使用 Photosphereviewer js 显示图像的应用程序。
我使用了 node.js 应用程序并将其上传到 Azure 网站(例如:http://example1.com)。 Photosphereviewer 中使用的图像来自另一个站点(例如:https://example2.com)。
现在,当我从http://example1.com 访问图像时,它会抛出如下错误
从原点访问“https://example2.com/images/1.JPG”处的图像 'http://example1.com' 已被 CORS 策略阻止:否 请求中存在“Access-Control-Allow-Origin”标头 资源。因此不允许使用原点“http://example1.com” 访问。
当我尝试使用内部另一个站点的图像时,它会正确显示图像而不会出错。
但是,当我在 Photosphereviewer 中使用如下图像时,它会引发 cors 错误:
var PSV = new PhotoSphereViewer({
panorama: 'https://example2.com/images/1.JPG',
container: 'photosphere',
caption: 'Images',
cors_anonymous: true,
checkImageOrigin: false,
// loading_img: 'http://photo-sphere-viewer.js.org/assets/photosphere-logo.gif',
navbar: 'autorotate zoom download caption', // fullscreen
// default_fov: 70,
mousewheel: false,
size: {
height: 520//472
}
});
我在 node js 应用的 app.js 中使用了 cors,如下所示:
app.use(cors());
app.use(function(req, res, next) {
res.header('Access-Control-Allow-Origin', '*'); // We can access from anywhere
res.header('Access-Control-Allow-Methods', 'GET,PUT,POST,DELETE,OPTIONS');
res.header('Access-Control-Allow-Headers', 'X-Requested-With, X-HTTP-Method-Override, Content-Type, Accept');
next();
});
在 Azure 网站中,我在 Api 部分下的 CORS 选项下包含了站点名称。
但没有一个有效。它会引发相同的错误。请帮助解决这个问题。提前致谢。
【问题讨论】:
-
嗨,你有什么更新吗?
标签: node.js azure express cors