Serve Command
The serve command starts a local development server that serves both your Angular build files and the Scully-generated static files.
Usage
Aliases: server, s
What It Does
The serve command:
- Starts a static file server for the Scully output directory
- Serves the generated HTML files
- Optionally opens a browser window
- Does not rebuild the project (use
--watch for that)
The serve command only serves existing files. It does not trigger a build. To automatically rebuild when files change, use the --watch flag.
Default Behavior
By default, the server:
- Serves files from
./dist/static
- Runs on
http://localhost:1668
- Logs warnings and errors only
Basic Options
Port
Specify a custom port:
npx scully serve --port=8080
Alias: -p
Host Name
Specify a custom hostname:
npx scully serve --host=0.0.0.0
This allows external access to the server.
Open Browser
Automatically open the default browser:
Aliases: -o, --openNavigator
Watch Mode
Automatically rebuild and reload when files change:
Alias: -w
When watch mode is enabled:
- Scully monitors your source files
- Automatically rebuilds when changes are detected
- Serves the updated files immediately
Watch Mode Controls
When running in watch mode, you can use keyboard shortcuts:
- r - Manually trigger a rebuild
- q - Quit and close the server
$ npx scully serve --watch
The server is available on "http://localhost:1668/"
------------------------------------------------------------
Press r for re-run Scully, or q for close the servers.
------------------------------------------------------------
SSL/HTTPS Support
Basic SSL
Enable SSL with a self-signed certificate:
Server will run on https://localhost:1668
Custom SSL Certificate
Provide your own SSL certificate and key:
npx scully serve --ssl --ssl-cert=./cert.pem --ssl-key=./key.pem
Options:
--ssl-cert - Path to SSL certificate file
--ssl-key - Path to SSL private key file
Proxy Configuration
Proxy API requests to a backend server:
npx scully serve --proxy=proxy.conf.json
Alias: --proxyConfigFile, --proxyConfig
Proxy Configuration File
Create a proxy.conf.json file:
{
"/api": {
"target": "http://localhost:3000",
"secure": false,
"changeOrigin": true
}
}
Scully uses the same proxy format as webpack-dev-server, powered by http-proxy-middleware.
404 Handling
Configure how the server handles 404 errors:
npx scully serve --handle404=index
Available options:
| Option | Behavior |
|---|
index | Serve /index.html for all 404s (SPA mode) |
baseOnly | Serve /index.html only for base route 404s |
404 | Serve /404.html if it exists |
none | Return standard 404 errors |
| “ (empty) | Use default behavior |
Examples
Single Page Application mode:
npx scully serve --handle404=index
Custom 404 page:
npx scully serve --handle404=404
Test Data Server
Start the built-in test data server for demos:
This provides mock API endpoints:
| Endpoint | Returns |
|---|
/users | List of users |
/users/:id | Single user by ID |
/posts | List of posts |
/posts/:id | Single post by ID |
/slow/:delay | 200 response after specified delay (ms) |
Example Usage
npx scully serve --tds
# Test the endpoints
curl http://localhost:1668/users
curl http://localhost:1668/posts/1
curl http://localhost:1668/slow/2000 # 2 second delay
Combined Examples
Development Server with Watch Mode
npx scully serve --watch --open
This will:
- Start the server
- Open your browser
- Watch for file changes and rebuild automatically
HTTPS Server with Custom Port
npx scully serve --ssl --port=8443 --open
Production-like Server
npx scully serve --prod --handle404=404
Development with API Proxy
npx scully serve --watch --proxy=proxy.conf.json --open
Server Configuration
Additional server options:
Server Timeout
Set timeout for server operations:
npx scully serve --serverTimeout=30000
Value in milliseconds. Default is 10000ms (10 seconds).
Static Folder
Serve from a custom output directory:
npx scully serve --folder=./dist/my-static
Logging Options
Reduce Logging
Show only warnings and errors:
Alias: --nl
Log Severity
Set specific log level:
npx scully serve --logSeverity=error
Options:
normal - Log everything
warning - Warnings and errors only (default)
error - Errors only
none - No logging
Stopping the Server
Graceful Shutdown
Press Ctrl+C or type q in watch mode.
Kill Background Server
If a server is running in the background:
Alias: ks
Or use the flag to automatically kill existing servers:
npx scully serve --killServer
Alias: --ks
Troubleshooting
Port Already in Use
If port 1668 is busy:
# Kill existing server
npx scully ks
# Or use a different port
npx scully serve --port=8080
Files Not Updating
Make sure you’re using watch mode:
SSL Certificate Errors
For self-signed certificates, you may need to accept the certificate in your browser or use:
# Chrome
chrome --ignore-certificate-errors
# Or provide valid certificates
npx scully serve --ssl --ssl-cert=./cert.pem --ssl-key=./key.pem
CI/CD Usage
For continuous integration:
# Build first
npx scully --noPrompt --prod
# Then serve (if needed for testing)
npx scully serve --noPrompt --port=8080
Next Steps