phasty-server
v0.2.0
Published
Fastify dev server with nginx-style try_files routing. Designed primarily for Laravel but usable for other apps.
Maintainers
Readme
phasty
Fastify dev server with nginx-style try_files routing. Designed for Laravel, works anywhere.
Serves static files, proxies everything else to php artisan serve, and optionally handles Vite HMR and HTTPS via Let's Encrypt.
Install
npm install --save-dev phasty-serverUsage
phasty start # reads phasty.config.js if present
phasty start --port=8080 --php-port=8081
phasty --help| Option | Default | Description |
|---|---|---|
| --port=N | auto | Fastify port |
| --php-port=N | auto | php artisan serve port |
| --php=path | php | PHP binary |
| --public-dir=dir | public | Static files root |
| --host=host | 0.0.0.0 | Bind address |
Routing
GET /css/app.css → public/css/app.css exists → sendFile
GET /login → no file, artisan running → proxy to PHP
GET /unknown → no file, no artisan → 404Configuration
Create phasty.config.js in the project root:
export default {
server: {
host: '0.0.0.0',
port: null, // auto
},
routing: {
publicDirs: ['public'],
},
php: {
enabled: true,
bin: 'php',
port: { start: 8000 },
},
vite: {
enabled: true,
port: { start: 5173 },
},
}Config priority: CLI args > phasty.config.js > ~/.phasty.yaml > defaults
For settings shared across projects (PHP binary, default host), create ~/.phasty.yaml:
php:
bin: /usr/local/bin/php8.3
server:
host: 0.0.0.0Vite
Phasty runs Vite as an internal process and exposes it through a separate proxy (HTTP + WebSocket for HMR).
Add to your vite.config.js:
server: {
origin: process.env.PHASTY_VITE_ORIGIN ?? 'http://localhost:5173',
hmr: process.env.PHASTY_DOMAIN
? {
protocol: 'wss',
host: process.env.PHASTY_DOMAIN,
clientPort: parseInt(process.env.PHASTY_VITE_PORT ?? '5173'),
}
: true,
}HTTPS
Requires certbot and certbot-dns-cloudflare. On startup, phasty obtains or renews the certificate automatically (renews if expiry < 14 days).
// phasty.config.js
export default {
https: {
enabled: true,
domain: 'example.com',
cert: {
email: '[email protected]',
certDomain: '*.example.com',
dns: {
credentialsFile: '~/.secrets/cloudflare.ini',
},
},
},
}If domain has no dot and certDomain is a wildcard (e.g. *.base.com), phasty resolves the full domain to domain.base.com automatically.
Requirements
- Node.js 18+
- Linux
- PHP (for Laravel mode)
- certbot + certbot-dns-cloudflare (for HTTPS)
