AppProxy
หน้าที่ของ resource proxy ถูกนิยามไว้ดังนี้
- เข้าถึงทรัพยากรข้ามโดเมน (CORS)
- ส่ง Request ที่มีความยาวเกิน 2048 ตัวอักษร หรือ Request แบบ POST ที่ต้องการส่งข้อมูลจำนวนมาก
- การเข้าถึง Secure Map Service ด้วย Token Based Authentication
ยังมีข้ออื่น ๆ อีก แต่ขอนำข้อที่จำเป็นต้องรู้เกี่ยวกับหน้าที่ของ Proxy Page ประมาณนี้
คอนฟิก proxy.config
ไฟล์คอนฟิกของ Proxy จะอยู่ในโฟล์เดอร์ Config โดย Development และ Production แยกไฟล์คอนฟิกกันชัดเจน
{
"allowedReferrers": ["https://atlasx.cdg.co.th"],
"tokenCacheMinutes": 29,
"serverUrls": [
{
"url": "https://appserver2.cdg.co.th/arcgis/rest/services/AtlasX/CITY",
"domain": "",
"username": "portaladmin",
"password": "portal123"
},
{
"url": "arcgis.com",
"clientId": "z3Cjsu3xPUEriYYq",
"clientSecret": "3691ba5e2f4747ccbe224477acca6a53",
"oauth2Endpoint": "https://www.arcgis.com/sharing/rest/oauth2/token"
}
]
}| Key | Description |
|---|---|
| allowedReferrers | รายการของ Client ที่อนุญาตให้ใช้งาน Proxy ได้ ในช่วง Development สามารถกำหนดเป็น * ได้เลย แต่ถ้าบน Production แนะนำให้ระบุ Domain Name ที่เราต้องการให้เข้าถึง Proxy ได้ |
| tokenCacheMinutes | เวลาที่ Token หมดอายุ นับจากเวลาที่ Proxy สร้าง Token |
| serverUrls | Profile ของ Map Service รองรับทั้ง ArcGIS Server และ OAuth 2.0 ของ ArcGIS Online หรือ Portal |
ตัวอย่างการเรียกใช้งาน
curl --location --request GET 'https://atlasx.cdg.co.th/axws-demo/api/AppProxy?https://appserver2.cdg.co.th/arcgis/rest/services/AtlasX/CITY/MapServer/legend?f=pjson' \
--header 'referer: https://atlasx.cdg.co.th/axws-demo' \
--header 'Content-Type: application/x-www-form-urlencoded' \
--data-urlencode 'f=json'