ζั͡ ั͡雾 ั͡狼 ั͡✾ 2022-08-03 09:14 采纳率: 50%
浏览 102
已结题

已拦截跨域资源请求,所有方法都试过了还是没用(后面有)。arcgis api for JS通过本地部署,再内网穿透发布到网络,本地服务器127.0.0.1能打开并显示,网络上映射的网站打开不了地图

问题遇到的现象和发生背景

已拦截跨域资源请求,所有方法都试过了还是没用(后面有)。arcgis api for JS通过本地部署,再内网穿透发布到网络,本地服务器127.0.0.1能打开并显示,网络上映射的网站打开不了地图,
内网穿透

img


node

img


本地服务器127.0.0.1正常

img


映射到网络上地图图层不显示

img

img

问题相关代码,请勿粘贴截图

已拦截跨源请求:同源策略禁止读取位于 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[]()**
###### 我想要达到的结果
  • 写回答

2条回答 默认 最新

  • ζั͡ ั͡雾 ั͡狼 ั͡✾ Unity2D领域新星创作者 2022-08-03 09:18
    关注

    img



    img


    后面俩张图片

    评论

报告相同问题?

问题事件

  • 已结题 (查看结题原因) 8月5日
  • 专家修改了标签 8月3日
  • 创建了问题 8月3日

悬赏问题

  • ¥15 已知平面坐标系(非直角坐标系)内三个点的坐标,反求两坐标轴的夹角
  • ¥15 webots有问题,无响应
  • ¥15 数据量少可以用MK趋势分析吗
  • ¥15 使用VH6501干扰RTR位,CANoe上显示的错误帧不足32个就进入bus off快慢恢复,为什么?
  • ¥15 大智慧怎么编写一个选股程序
  • ¥100 python 调用 cgps 命令获取 实时位置信息
  • ¥15 两台交换机分别是trunk接口和access接口为何无法通信,通信过程是如何?
  • ¥15 C语言使用vscode编码错误
  • ¥15 用KSV5转成本时,如何不生成那笔中间凭证
  • ¥20 ensp怎么配置让PC1和PC2通讯上