iOS creating local server to run application


#1

Hello there!

I’m running my application in an iOS device and the device is just creating a local server to run the application. This is screwing up my connection with the server.

Does anyone know how to solve this?


#2

How do you connect to that server? Using localhost?

Wkwebview indeed creates a sandboxed server to serve the webapp, which shpuld not give issues connecting to other endpoints using http


#3

@Tommertom thanks for your answer.
Right now it is trying to use localhost because iOS is creating a local server to serve the app, my question is: can iOS run it like android does? Without creating a local server?


#4

Well, I was forced to enable CORS on my api. I didn’t really wanted to do that, but I had to.

For anyone who would be looking for this solution, in Laravel 5.5:

app/http/middleware

<?php
// /app/Http/Middleware/Cors.php 
namespace App\Http\Middleware;
 
use Closure;
 
class Cors {
    public function handle($request, Closure $next)
    {
        return $next($request)
            ->header('Access-Control-Allow-Origin', 'http://localhost:8080') //or the url you want. * for all urls
            ->header('Access-Control-Allow-Methods', 'GET, POST, PUT, DELETE, OPTIONS');
    }
}

bootstrap/app.php:

$app->middleware([ //add this to your file
    App\Http\Middleware\Cors::class //or just add this line in case you are already using some middleware
 ]);