Skip to main content

Serve Command

The serve command starts a local development server that serves both your Angular build files and the Scully-generated static files.

Usage

npx scully serve
Aliases: server, s

What It Does

The serve command:
  1. Starts a static file server for the Scully output directory
  2. Serves the generated HTML files
  3. Optionally opens a browser window
  4. 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
npx scully serve -p 8080

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:
npx scully serve --open
Aliases: -o, --openNavigator
npx scully serve -o

Watch Mode

Automatically rebuild and reload when files change:
npx scully serve --watch
Alias: -w
npx scully serve -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:
npx scully serve --ssl
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:
OptionBehavior
indexServe /index.html for all 404s (SPA mode)
baseOnlyServe /index.html only for base route 404s
404Serve /404.html if it exists
noneReturn 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:
npx scully serve --tds
This provides mock API endpoints:
EndpointReturns
/usersList of users
/users/:idSingle user by ID
/postsList of posts
/posts/:idSingle post by ID
/slow/:delay200 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:
  1. Start the server
  2. Open your browser
  3. 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:
npx scully serve --noLog
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:
npx scully killServer
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:
npx scully serve --watch

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

Build docs developers (and LLMs) love