【发布时间】:2021-12-11 06:50:10
【问题描述】:
我正在开发一个颤振的 Web 应用程序。我想防止我的 API 端点在 https:// 或 http:// 上运行时出现 CORS 错误 如何修改下面的端点类以根据当前的window.location.protocol? 这是我的服务类:
import 'package:universal_html/html.dart';
class ApiEndPoint {
Location currentLocation = window.location;
static
const host = 'api.xyz.com';
static
const http = 'http://';
static
const https = 'https://';
static String baseUrl = "";
// get base {
// if (currentLocation.protocol == 'https') {
// return baseUrl = "$https$host/api";
// } else if (currentLocation.protocol == 'http') {
// return baseUrl = "$http$host/api";
// }
// }
}
【问题讨论】:
标签: api dart flutter-web window.location