Slimframeworrk only accesses by duplicating bars in the URL

Asked

Viewed 24 times

0

I am using Slimframework and I have the following code:

<?php   

    use Psr\Http\Message\ServerRequestInterface as Request;
    use Psr\Http\Message\ResponseInterface as Response;
    use Slim\Http\UploadedFile;

     $mid01 = function(Request $request, Response $response, $next):      Response{

        $response->getBody()->write("BEFORE<br>");
        $response = $next($request, $response);
        $response->getBody()->write("AFTER<br>");

        return $response;

    };

    $app = new \Slim\App();

     $app->post('/file', function(Request $request, Response $response, array $args){
        
        $uploadedFiles = $request->getUploadedFiles();
        $response->getBody()->write("API<br>");
        return $response;

    })->add($mid01);

    $app->run();

Then I run the following command to start the server:

/var/www/apiFiles/api$ php -S 0.0.0.0:3131 -t src ./src/api.php

The Server starts normally and I can give a POST through a hostname, such as:

api.empresaXXX.com.br:3131

The point is, when I try to access the route http://api.empresaXXX.com.br:3131/file, I get the following error:

slimError1

However, if I give a POST on http://api.empresaXXX.com.br:3131//file, duplicating the bars, he accesses:

inserir a descrição da imagem aqui

Any suggestions as to how I can proceed in this case?

1 answer

0

I ended up finding the solution to the problem.

Apparently Slim requires the server file to have the name of:

index.php

I changed it to index.php and ran the command:

php -S 0.0.0.0:3131 -t src src/index.php

Worked!

Browser other questions tagged

You are not signed in. Login or sign up in order to post.