मेरे पास node.js सर्वर 0.10.12 और express.js 4.8.5 है। Node.js वेब सर्वर है, इसमें ओपनलेयर 3.9.0 शामिल हैं।node.js और geoserver CORS
जियोसरवर 2.1.3 डब्लूएमएस परत की सेवा करता है। बाद में, मैं वेक्टर परतों को लागू करूंगा।
केवल एक ही मार्ग (अनुक्रमणिका पृष्ठ के लिए)
var routes = require('./routes/index');
index.js
var express = require('express');
var router = express.Router();
router.get('/', function(req, res, next) {
res.render('index', { title: 'openlayers3 testing', head: 'Welcome' });
next();
});
module.exports = router;
शामिल तो app.js
var routes = require('./routes/index');//explained above
var app = express();
// view engine setup
app.set('views', path.join(__dirname, 'views'));
app.set('view engine', 'ejs');
app.use(favicon());
app.use(logger('dev'));
app.use(bodyParser.json());
app.use(bodyParser.urlencoded());
app.use(cookieParser());
app.use(express.static(path.join(__dirname, 'public')));
है मैं CORS
निम्नलिखित जोड़ा जाता हैapp.use(function (req, res, next) {
res.setHeader('Access-Control-Allow-Origin', '*');
res.setHeader('Access-Control-Allow-Methods', 'GET, POST, OPTIONS, PUT, PATCH, DELETE');
res.setHeader('Access-Control-Allow-Headers', 'X-Requested-With,content-type');
res.setHeader('Access-Control-Allow-Credentials', true);
next();
});
app.get('/', routes);
और index.ejs
में मैं इस
var ait = new ol.layer.Tile({
extent: textent,
source: new ol.source.TileWMS({
url: 'http://localhost:8080/geoserver/mymap/wms',
crossOrigin: 'anonymous',
attributions: [new ol.Attribution({
html: '© ' +'<a href="http://www.geo.admin.ch/internet/geoportal/' +'en/home.html">' +'National parks/geo.admin.ch</a>'
})],
params: {'LAYERS': 'mymap:planet_osm_polygon, mymap:planet_osm_line, mymap:planet_osm_roads, mymap:planet_osm_point'},
serverType: 'geoserver'
})
})
की तरह मेरे Geoserver WMS स्तर सेट और मैं त्रुटि
Image from origin 'http://localhost:8080' has been blocked from loading by Cross-Origin Resource Sharing policy: No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'http://localhost:5550' is therefore not allowed access.
मैं विविधताओं का एक बहुत कोशिश की मिल मुझे ऑनलाइन मिला। मैंने app.use(express.static(path.join(__dirname, 'public')));
से पहले कोड डाला। मैंने इसे index.js
के router.get
के अंदर रखा। अब तक कुछ भी नहीं। मैं समझने में असफल रहा कि क्या गलत है।
धन्यवाद
नोटों
यह इंटरनेट एक्सप्लोरर 11. कोई त्रुटि नहीं में काम करता है और मैं वास्तव में फ़ायरफ़ॉक्स 30 में परत
कोई त्रुटि नहीं देख सकते हैं, लेकिन मैं परत
नहीं देख सकते हैंक्रोम 45 में मैं परत नहीं देख सकता और मुझे वह त्रुटि मिलती है
क्या आपने देखा - https://stackoverflow.com/a/25025579/4640499? –
@ स्लेविन आप गलत पक्ष पर सीओआरएस जोड़ रहे हैं। आप नोड ऐप से अपने जियोसरवर से कनेक्ट कर रहे हैं। तो, आपके Geoserver में CORS को जोड़ा जाना चाहिए, नोड ऐप पर नहीं। – hassansin
@ जोनाटावाकर हाँ, धन्यवाद, मैं इस – slevin