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

Add an ssg:serve command for local testing #121

Merged
merged 2 commits into from
Nov 16, 2022

Conversation

jacksleight
Copy link
Contributor

When developing locally it can be useful to test out the SSG and its generated output, but you can't just open the site up in a browser as all the links and asset URLs are absolute and have to point to a real host.

This PR adds an ssg:serve command that launches the PHP dev server in the SSG destination folder.

The way I'm using this is by creating a .env.serve file:

APP_NAME="Example"
APP_ENV=production
APP_DEBUG=false
APP_URL=http:https://127.0.0.1:8000
...

Then running:

php please ssg:generate --env=serve
php please ssg:serve

The command itself is just a stripped down and tweaked version of Laravel's serve command.

@what-the-diff
Copy link

what-the-diff bot commented Nov 16, 2022

  • Added a new command to serve the static site on PHP's built-in development server.
  • Registered that command in ServiceProvider::boot().
  • Created a file for serving requests with PHP's built-in web server, which is used by the new "serve" command above (src/resources/server.php). This allows us to emulate Apache's mod_rewrite functionality from within this simple HTTP server and provides an easy way of testing our application without having installed any other real web servers here locally or elsewhere where we might be deploying it later on down the road when using Statamic as a headless CMS solution instead of just running it like you would normally do if you were building your own custom Laravel app from scratch yourself manually step by step one line at time starting out with something like:

@jasonvarga
Copy link
Member

Rad! I had wanted to do this for a while. I actually find myself running ssg:serve thinking it already existed.

Shame we need to reinvent the command. It would be neat if you artisan serve could be given a directory. Oh well.

@jacksleight
Copy link
Contributor Author

jacksleight commented Nov 16, 2022

Yeah that was my first thought too! I did consider extending the Laravel command and just overriding the startProcess method, but that felt a bit untidy. And the Laravel command is doing a bunch of stuff that's not really needed here.

@jasonvarga jasonvarga merged commit 671dc79 into statamic:master Nov 16, 2022
@jacksleight jacksleight deleted the ssg-serve-command branch November 16, 2022 19:00
@jacksleight
Copy link
Contributor Author

Don't suppose this could be released?

@jasonvarga
Copy link
Member

Whoops, sorry 😬 Tagged now.

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

Successfully merging this pull request may close these issues.

None yet

2 participants