BSSG Experimental Feature: Built-in Local Development Server
I'm excited to share a new experimental feature recently pushed to the BSSG repository: a built-in local development server! While this isn't part of an official numbered release yet, it's available on the main branch for those who like to live on the edge and want to simplify their local development workflow.
This new addition aims to make previewing your BSSG site quicker and more convenient:
You can now easily build and serve your site locally with a single command:
- Run
./bssg.sh server
from your BSSG directory. - This command first triggers a full build of your site.
- Then, it starts a simple Bash-based HTTP server (powered by
socat
ornetcat
, but with some limits) to serve your generatedoutput/
directory.
One of the neatest parts of this feature is how it handles your site's base URL:
- When you run
./bssg.sh server
, the build process will temporarily use aSITE_URL
that matches the local server's address (e.g.,http://localhost:8000
). - This means all your internal links, asset paths, and canonical URLs will be correctly formed for the local preview environment, without you needing to change your main
SITE_URL
(which should point to your final production URL).
The server comes with a few handy options:
--port <PORT>
: Specify a custom port for the server (default is8000
, configurable viaBSSG_SERVER_PORT_DEFAULT
inconfig.sh.local
).--host <HOST>
: Specify a custom host/IP for the server (default islocalhost
, configurable viaBSSG_SERVER_HOST_DEFAULT
inconfig.sh.local
).--no-build
: Skip the initial build step and serve the existing content in youroutput/
directory. Useful if you've just run a build and want to quickly restart the server.-h, --help
: Displays detailed help for theserver
command.
Important Considerations & How to Use
This feature is experimental:
- Socat Dependency: The server relies on
socat
being installed on your system. It will fallback to netcat, but it won't work properly as won't manage concurrent requests. I've put effort into making the script detect variousnc
versions (GNU, OpenBSD, Apple, traditional), but given the wide variety ofnc
implementations, there might still be edge cases. If you encounter issues, please report them! - Basic Server: The included HTTP server is very basic, designed for local previewing. It handles GET requests for static files and common MIME types. It's not intended as a production server.
To use it:
- Ensure you have the latest code from the BSSG repository.
- Navigate to your BSSG installation.
- Run
./bssg.sh server
. - Open your browser to
http://localhost:8000
(or the host/port you specified).
You should see your site, with all links working relative to the local server address.
You can set the default port and host for the server in your config.sh.local
:
# Default port for './bssg.sh server'
BSSG_SERVER_PORT_DEFAULT="8080"
# Default host for './bssg.sh server'
BSSG_SERVER_HOST_DEFAULT="192.168.1.2" # To make it accessible on your local network - change with your local IP address
This feature is fresh out of the development oven and ready for some real-world testing. I encourage you to try it out for your local BSSG development. Your feedback, bug reports, and suggestions are invaluable as I work towards making it a stable part of a future release.
You can find the latest code and report issues on the BSSG project page.
Happy local developing!
Stefano