我有一个Angularjs项目。我使用gulp服务构建它。我,使用ckeditor上传远程服务器上的文件,我收到此错误:
Permission denied to access property "CKEDITOR" on cross-origin object
我的gulp server.js文件如下
'use strict';
var path = require('path');
var gulp = require('gulp');
var conf = require('./conf');
var browserSync = require('browser-sync');
var browserSyncSpa = require('browser-sync-spa');
var util = require('util');
var proxyMiddleware = require('http-proxy-middleware');
function browserSyncInit(baseDir, browser) {
browser = browser === undefined ? 'default' : browser;
var routes = null;
if(baseDir === conf.paths.src || (util.isArray(baseDir) &&
baseDir.indexOf(conf.paths.src) !== -1)) {
routes = {
'/bower_components': 'bower_components'
};
}
var server = {
baseDir: baseDir,
middleware: function (req, res, next) {
res.setHeader('Access-Control-Allow-Origin', '*');
res.setHeader('Access-Control-Allow-Headers', '*');
res.setHeader('Access-Control-Allow-Methods', 'GET,OPTIONS, POST, PUT');
res.setHeader('Access-Control-Allow-Credentials', 'GET,OPTIONS, POST, PUT');
next();
},
routes: routes
};
browserSync.instance = browserSync.init({
startPath: '/',
server: server,
browser: browser,
ghostMode: false
});
}
browserSync.use(browserSyncSpa({
selector: '[ng-app]'// Only needed for angular apps
}));
gulp.task('serve', ['watch'], function () {
browserSyncInit([path.join(conf.paths.tmp, '/serve'), conf.paths.src]);
connect.server(server);
});
gulp.task('serve:dist', ['build'], function () {
browserSyncInit(conf.paths.dist);
connect.server(server);
});
gulp.task('serve:e2e', ['inject'], function () {
browserSyncInit([conf.paths.tmp + '/serve', conf.paths.src], []);
connect.server(server);
});
gulp.task('serve:e2e-dist', ['build'], function () {
browserSyncInit(conf.paths.dist, []);
connect.server(server);
});
但是“Access-Control-Allow-Origin”,“*'”未在标题中设置,我仍然会收到该错误!
当页面加载Http响应和请求标题如下:
响应标题:
Access-Control-Allow-Origin *
Access-Control-Allow-Headers *
Access-Control-Allow-Methods GET,OPTIONS, POST, PUT
Access-Control-Allow-Credentials true
Accept-Ranges bytes
Cache-Control public, max-age=0
Last-Modified Wed, 11 Oct 2017 05:56:16 GMT
ETag W/"91a-15f0a01475b"
Date Sat, 14 Oct 2017 05:03:02 GMT
Connection keep-alive
请求标题:
Host localhost:3000
User-Agent Mozilla/5.0 (X11; Ubuntu; Linu…) Gecko/20100101 Firefox/56.0
Accept application/json, text/plain, */*
Accept-Language en-US,en;q=0.5
Accept-Encoding gzip, deflate
Referer http://localhost:3000/
Cookie language=fa; io=qkk4hCbXxaQ78a…FxfKICyH9dwHZOr5m2aJJ89Z0DS2H
Connection keep-alive
If-Modified-Since Wed, 11 Oct 2017 05:56:16 GMT
If-None-Match W/"91a-15f0a01475b"
谢谢:)
我还使用了CORS Everywhere Firefox附加组件。但它没有用