Deployment
Coming Soon
This guide is currently under development. Check back soon for comprehensive deployment documentation including:
- Building for Production
- Docker Deployment
- Environment Configuration
- Performance Optimization
- Security Best Practices
- CI/CD Pipelines
- Monitoring and Logging
Quick Start
Check the project first — the mistakes that only surface in production are exactly the ones doctor looks for, and it exits non-zero so it fits in a CI step:
asena doctorThen build your application:
asena buildThen run the production build:
bun dist/index.asena.jsThree things worth checking before a first production deploy
buildOptions.minify.identifiersmust befalse. Component names are read at runtime, and a bundle built with identifiers minified fails to resolve them — in production only. The build forces it off andasena doctorreports it.keepNames: truedoes not substitute for it. See Minification and component names.- One copy of
@asenajs/asena,honoandzodeach. Two copies breakinstanceofand theHttpExceptionbrand, turning a deliberate404into a500with no clue as to why.asena doctorchecks for this. @Protectedroutes need their guard. The marks are metadata; without asena-auth's guard inimports, those routes are served open.asena doctorreports it asauth-enforcement. See Authentication.
For a smaller entry file and a faster startup, enable buildOptions.splitting. The build then writes chunk files next to index.asena.js, so ship the whole dist/ directory rather than the single file.
Graceful Shutdown and Probes
Two things a deployment needs are already available:
- Signals are handled by default.
SIGTERM,SIGINTandSIGHUPcallserver.stop(), which stops taking new work, runs your components'@OnStophooks while the transports are still up, then releases everything in order. See Component Lifecycle. - Liveness and readiness are separate endpoints. Pass
health: { port }and point your restart policy at{path}/liveand your load balancer at{path}/ready. Readiness answers503for the whole drain, so an instance is pulled from rotation while it still has work to finish. See Health probes.
Sessions Behind a Proxy
With asena-auth's native sessions behind a load balancer or a TLS-terminating proxy:
Keep the cookie
Secure. The session cookie isSecureby default, and browsers accept it because they talk HTTPS to the proxy; the plain-HTTP hop behind it does not matter.asena doctorfailsauth-cookieon cookie options browsers reject, such assameSite: 'none'withsecure: false.List your public origin for older browsers. The app sees
http://request URLs while browsers send anhttps://Origin. Browsers that sendSec-Fetch-Sitepass the cross-site check on that header alone; for those that do not, list your public origin intrustedOrigins.X-Forwarded-*headers are not read.typescript@Auth({ csrf: { trustedOrigins: ['https://app.example.com'] } }) export class AppAuth extends AsenaAuthService {}Share the session store. The default
MemoryAuthStorelives in one process: a session created on one instance is unknown to the others, and every session is lost on restart. Pass a store over your database or Redis - see Custom Session Store.
Related
- Asena Auth - Cookie options, the cross-site check and session stores
- CLI Build Command - Building a production bundle
- asena doctor - Pre-flight check for the project's configuration
- CLI Configuration - Build options and output
- Server Configuration - Runtime server settings
- Component Lifecycle - Graceful shutdown, signals and health probes
- GitHub - Follow the repository for updates