Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Issue building sites using ApiPlatform #179

Open
tacman opened this issue Nov 6, 2023 · 1 comment
Open

Issue building sites using ApiPlatform #179

tacman opened this issue Nov 6, 2023 · 1 comment

Comments

@tacman
Copy link

tacman commented Nov 6, 2023

I have a simple site that I'd like to build as a set of static page. It's failing when trying to generate the API platform routes, and I'm not sure how to exclude them. Obviously API Platform is going to require an actual server, but I think the issue is with the documentation, which ideally would work with static files. Regardless, I would like to be able to exclude it so the rest of the site builds.

"channel":"console","datetime":"2023-11-06T16:53:17.709953+00:00","extra":{}}
16:53:17 CRITICAL  [console] Error thrown while running command "-e prod stenope:build './public/static'". Message: "Could not build url http://localhost/api/index.jsonopenapi." ["exception" => Exception { …},"command" => "-e prod stenope:build './public/static'","message" => "Could not build url http://localhost/api/index.jsonopenapi."]
{"message":"Command \"-e prod stenope:build './public/static'\" exited with code \"1\"","context":{"command":"-e prod stenope:build './public/static'","code":1},"level":100,"level_name":"DEBUG","channel":"console","datetime":"2023-11-06T16:53:17.715661+00:00","extra":{}}
In Builder.php line 386:
                                                               
  Could not build url http://localhost/api/index.jsonopenapi.  
                                                               

Here's the bash commands to create the problem.

symfony new crawler-7 --webapp --version=next --php=8.2 && cd crawler-7
composer config extra.symfony.allow-contrib true
echo "DATABASE_URL=sqlite:///%kernel.project_dir%/var/data.db" > .env.local
composer req api
composer require orm-fixtures --dev            
echo "officialName,string,48,no," | sed "s/,/\n/g"  | bin/console make:entity Official
bin/console doctrine:schema:update --force --complete

bin/console make:crud Official -q
bin/console make:fixture CongressFixtures
cat > src/DataFixtures/AppFixtures.php <<'END'
<?php

namespace App\DataFixtures;

use App\Entity\Official;
use Doctrine\Bundle\FixturesBundle\Fixture;
use Doctrine\Persistence\ObjectManager;

class AppFixtures extends Fixture
{
    public function load(ObjectManager $manager): void
    {
        $url = 'https://theunitedstates.io/congress-legislators/legislators-current.json';
        $json = file_get_contents($url);
        foreach (json_decode($json) as $record) {
            $name = $record->name;
            $official = (new Official())
                ->setOfficialName($name->official_full ?? "$name->first $name->last");
            $manager->persist($official);
        }
    $manager->flush();
    }
}
END

bin/console d:fixtures:load -n

composer require stenope/stenope
bin/console -e prod cache:clear
bin/console -e prod stenope:build ./public/static
@tacman
Copy link
Author

tacman commented Nov 7, 2023

I was able to exclude the API routes

# config/routes/api_platform.yaml 
api_platform:
    resource: .
    type: api_platform
    prefix: /api
    options:
        expose: true
        stenope:
            ignore: true

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant