问题遇到的现象和发生背景
已拦截跨域资源请求,所有方法都试过了还是没用(后面有)。arcgis api for JS通过本地部署,再内网穿透发布到网络,本地服务器127.0.0.1能打开并显示,网络上映射的网站打开不了地图,
内网穿透
node
本地服务器127.0.0.1正常
映射到网络上地图图层不显示
问题相关代码,请勿粘贴截图
已拦截跨源请求:同源策略禁止读取位于 http://localhost/4.9/esri/themes/base/fonts/avenir-next/Avenir_Next_W00_400.ttf 的远程资源。(原因:CORS 头缺少 'Access-Control-Allow-Origin')。状态码:200。
附上我的arcgis api代码
javascript
require([
"esri/config",
"esri/Map",
"esri/views/MapView",
"esri/Graphic",
"esri/layers/GraphicsLayer"
], function(esriConfig,Map, MapView, Graphic, GraphicsLayer) {
esriConfig.apiKey = "YOUR_API_KEY";
const map = new Map({
basemap: "streets" //Basemap layer service
});
const view = new MapView({
map: map,
center: [-118.80500,34.02700], //Longitude, latitude
zoom: 13,
container: "viewDiv"
});
//图层
const graphicsLayer = new GraphicsLayer();
map.add(graphicsLayer);
//多点显示位置
getpoint();
const point = { //Create a point
type: "multipoint",
points:multipoint,
};
const simpleMarkerSymbol = {
type: "simple-marker",
color: [226, 119, 40], // Orange
outline: {
color: [255, 255, 255], // White
width: 1
}
};
const pointGraphic = new Graphic({
geometry: point,
symbol: simpleMarkerSymbol
});
graphicsLayer.add(pointGraphic);
// Create a line geometry
const polyline = {
type: "polyline",
paths: [
[-118.821527826096, 34.0139576938577], //Longitude, latitude
[-118.814893761649, 34.0080602407843], //Longitude, latitude
[-118.808878330345, 34.0016642996246] //Longitude, latitude
]
};
const simpleLineSymbol = {
type: "simple-line",
color: [226, 119, 40], // Orange
width: 2
};
const polylineGraphic = new Graphic({
geometry: polyline,
symbol: simpleLineSymbol
});
graphicsLayer.add(polylineGraphic);
// Create a polygon geometry
const polygon = {
type: "polygon",
rings: [
[-118.818984489994, 34.0137559967283], //Longitude, latitude
[-118.806796597377, 34.0215816298725], //Longitude, latitude
[-118.791432890735, 34.0163883241613], //Longitude, latitude
[-118.79596686535, 34.008564864635], //Longitude, latitude
[-118.808558110679, 34.0035027131376] //Longitude, latitude
]
};
const simpleFillSymbol = {
type: "simple-fill",
color: [227, 139, 79, 0.8], // Orange, opacity 80%
outline: {
color: [255, 255, 255],
width: 1
}
};
const popupTemplate = {
title: "{Name}",
content: "{Description}"
}
const attributes = {
Name: "Graphic",
Description: "I am a polygon"
}
const polygonGraphic = new Graphic({
geometry: polygon,
symbol: simpleFillSymbol,
attributes: attributes,
popupTemplate: popupTemplate
});
graphicsLayer.add(polygonGraphic);
});
###### 运行结果及报错内容
本地服务器127.0.0.1能打开并显示,网络上映射的网站打开不了地图
###### 我的解答思路和尝试过的方法
查阅所有资料
**1.修改过本地api IIS中的请求头和MIME类型**
![img](https://img-mid.csdnimg.cn/release/static/image/mid/ask/808990884956168.png "#left")
![img](https://img-mid.csdnimg.cn/release/static/image/mid/ask/531661884956159.png "#left")
**2.node服务器增添过cors模块和req.header(...)**
const express=require('express')
const app=express()
const joi =require('joi')
app.use(express.static('./public',{index:"login.html"}))
app.use( function (req, res, next) {
res.header('Access-Control-Allow-Origin', '*');
res.header('Access-Control-Allow-Headers', 'xCors,Content-Type, Content-Length, Authorization, Accept, X-Requested-With , yourHeaderFeild');
res.header('Access-Control-Allow-Methods', 'PUT, POST, GET, DELETE, OPTIONS');
if (req.method == 'OPTIONS') {
res.send(200);
} else {
next();
}
});
const cors=require('cors')
app.use(cors())
app.use(express.urlencoded({extended:false}))//解析x-www-form-urlencoded格式表单数据
app.use((req,res,next)=>{
res.cc=function(err,status=1){
res.send({status,
messages:err instanceof Error ? err.message : err})
}
next()
})
const expressJWT=require('express-jwt')
const config=require('./config')
app.use(expressJWT({
secret:config.jwtSecreKey
}).unless({
path:[/^\/api/]
}))
const userRouter=require('./router/user')
app.use('/api',userRouter)
const userinfoRouter=require('./router/userinfo')
app.use('/my',userinfoRouter)
//错误级别中间件
app.use((err,req,res,next)=>{
if(err instanceof joi.ValidationError) return res.cc(err)
if(err.name==='UnauthorizedError') return res.cc('身份认证失败!')
res.cc(err)
})
app.listen(3007,()=>{
console.log('run http://127.0.0.1:3007')
})
**3.火狐浏览器去一个网站设置过一个参数为flase[]()**
###### 我想要达到的结果