React Router
React Router applications on monolayer
This section describes the integration of React Router applications on monolayer, including supported platform capabilities, automatic database detection, and custom launch configurations using a Procfile.
Introduction to React Router on monolayer
React Router is a flexible library and full-stack framework for React applications. monolayer provides robust support for React Router applications, featuring automatic configuration of database services and customizable launch environments.
When you deploy a React Router application, monolayer automatically builds your static assets and configures the runtime environment to serve your application efficiently.
React Router Platform Capabilities
Your React Router application has access to various platform capabilities. While some advanced integrations are currently under development, the core database and lifecycle functionalities are fully supported.
Managed PostgreSQL Database
monolayer automatically provisions a fully managed PostgreSQL database when it detects PostgreSQL usage in your React Router project.
- Automatic detection. The system checks your project dependencies for PostgreSQL database drivers.
- Database provisioning. Upon detection, monolayer provisions a PostgreSQL database in your AWS account.
- Connection injection. monolayer injects secure database access details into your environment variables automatically, ensuring that no manual database configuration is needed.
Detection Conditions
monolayer automatically detects your database configuration when your project satisfies the following conditions:
- Server-Side Rendering (SSR): Your React Router configuration must either omit the
ssroption or setssr: true. - Database dependencies: Your project must define either
pgorpostgresas a dependency in yourpackage.jsonfile.
When monolayer detects PostgreSQL usage, it automatically creates the following database lifecycle workloads:
- Database creation (
createDatabase):- If your
package.jsoncontains adb:createscript, the workload runsdb:create. - If
db:createis missing butdb:migrateexists, the workload runsdb:migrate. - This lifecycle workload runs only once.
- If your
- Database migrations (
migrateDatabase):- If your
package.jsoncontains adb:migrateentry, the workload runsdb:migrate. - This lifecycle workload runs before deploying the application.
- If your
Runtime Environment Variables
At runtime, monolayer automatically injects the following environment variables into your application environment:
DATABASE_URL: The full connection string used to connect to your PostgreSQL database.PGPASSWORD: The secure password for database authentication.PGUSER: The username for your database.PGHOST: The endpoint host address of your database.PGPORT: The port number used to connect to your database instance.PGDATABASE: The name of your PostgreSQL database.
Application Lifecycle Workloads
You can execute custom scripts and tasks during specific phases of your deployment lifecycle. For more information on process configurations, see the Procfile Guide.
- Deployment orchestration. You can run database migrations or prepare data using Procfile-managed commands before or after your web server starts.
- Zero-ops environment. The platform coordinates the initialization of resources so your lifecycle scripts execute in the correct order.
For React Router applications, you can define custom processes in a root Procfile to run lifecycle workloads when deploying your application.
bootstrap: _your-command_
beforeRollout: _your-command_
afterRollout: _your-command_
createDatabase: _your-command_
migrateDatabase: _your-command_Capabilities Roadmap
Support for the remaining monolayer platform capabilities is actively being developed. The following services will be available soon:
- Asynchronous background tasks. Support for offloading background tasks and queuing work asynchronously is coming soon.
- Real-time communications. Native real-time WebSocket support is coming soon.
- Scheduled cron jobs. Running scheduled tasks using cron syntax is coming soon.
- Object storage with buckets. Secure object storage backed by Amazon Simple Storage Service (Amazon S3) is coming soon.