Svelte 3 + slimPHP 4 : Guidance

Hello all, just wondering if anyone else here has done something similar?

Essentially I’ve written a backend API using slim 4, secured with Tuupola’s excellent JWT middleware.

The front end is written in Svelte and the index.html is served up by slim when you hit the / path. Note: I’m using svelte-routing for client side routing. eg:

    $app->get('/', function (Request $request, Response $response, $args) {
      $response->getBody()->write(file_get_contents('./index.html', true));
      return $response;
    });

I’m hosting the app as a docker container using trafex/alpine-nginx-php7 image.

It all works well with the exception of one irksome problem: Once you’re on a client route other than “/”, hitting browser refresh returns a server side 404 or 401. Yes F5 hits the server and thats why.

Is there some other configuration I need to consider?

I know I can split front and backend into separate containers which would avoid this problem, however I am hoping to keep this in one repo and one build for simplicity’s sake (I’m writing it for a friend) if possible.

Calling out any other gotcha’s would also be welcome.

If I can solve this, my intention is to publish (yet another) slim4 starter repo.

Cheers