解析期间离线Http失败时不在livereload或local

内容来源于 Stack Overflow,并遵循CC BY-SA 3.0许可协议进行翻译与使用

  • 回答 (1)
  • 关注 (0)
  • 查看 (25)

只有当我编译我的应用程序时才会ionic cordova run android出现此错误

如果我用--livereload它编译它不会发生,我使用代理来解决CORS问题

{
  "name": "gestor",
  "type": "ionic-angular",
  "integrations": {
    "cordova": {}
  },
  "proxies": [
    {
      "path": "/api",
      "proxyUrl": "https://gestor2.siacomsistemas.com.br/api"
    }
  ]
}
提问于
用户回答回答于

问题是,对于生产我不能使用代理,所以我需要测试我何时创建URL

    protected baseApi = "/api/";

    constructor(protected platform: Platform) {
        if (platform.is('cordova')) {
            this.baseApi = "https://gestor2.siacomsistemas.com.br/api/";
        }
    }

并且CORs问题在我的api服务器端,我正在使用laravel并且需要创建一个CORs中间件

\\app\Http\Middleware\Cors.php

<?php

namespace App\Http\Middleware;

use Closure;


class Cors {

    public function handle($request, Closure $next)
    {
        return $next($request)
            ->header('Access-Control-Allow-Origin', '*')
            ->header('Access-Control-Allow-Methods', 'GET, POST, PUT, DELETE, OPTIONS')
            ->header('Access-Control-Allow-Headers', 'Content-Type, Accept, Authorization, X-Requested-With, XMLHttpRequest');
    }
}

并在我的内核上调用它

\\app\Http\Kernel.php

    protected $middleware = [
        \Illuminate\Foundation\Http\Middleware\CheckForMaintenanceMode::class,
        \Illuminate\Foundation\Http\Middleware\ValidatePostSize::class,
        \App\Http\Middleware\TrimStrings::class,
        \Illuminate\Foundation\Http\Middleware\ConvertEmptyStringsToNull::class,
        \App\Http\Middleware\TrustProxies::class,
        \App\Http\Middleware\HttpsProtocol::class,
        \App\Http\Middleware\Cors::class,
    ];

扫码关注云+社区

领取腾讯云代金券