Configuration
DolphJS uses a central configuration file named dolph_config.yaml. This file sits at the root of your project and dictates how the DolphFactory initializes the server, databases, and middleware.
Basic Configuration
Section titled “Basic Configuration”A standard dolph_config.yaml looks like this:
database: mongo: url: mongodb://localhost:27017/dolph_db options: useNewUrlParser: true useUnifiedTopology: true mysql: host: localhost user: root password: password database: dolph_db
server: port: 3300 host: localhost env: development
middlewares: cors: origin: "*" credentials: true helmet: true jsonParser: true urlEncoded: trueEnvironment Variables
Section titled “Environment Variables”DolphJS automatically merges your .env files with your configuration. You can reference environment variables within your application using standard process.env properties, or you can rely on the factory to inject these values directly.
Configuration Sections
Section titled “Configuration Sections”Server
Section titled “Server”Controls the core HTTP server bindings.
- port: The port your application will listen on. Defaults to
3000. - host: The host to bind to.
- env: The running environment (e.g.,
development,production). Inproduction, DolphJS disables certain verbose logging mechanisms to boost performance.
Database
Section titled “Database”DolphJS provides out-of-the-box auto-initialization for MongoDB and MySQL.
Middlewares
Section titled “Middlewares”DolphJS bundles commonly used Express middlewares. You can toggle them in your config:
- cors: Configures Cross-Origin Resource Sharing.
- helmet: Secures your Express apps by setting various HTTP headers.
- jsonParser: Automatically parses incoming requests with JSON payloads (uses
express.json()). - urlEncoded: Parses URL-encoded bodies (uses
express.urlencoded()).
Accessing Configuration in Code
Section titled “Accessing Configuration in Code”While dolph_config.yaml drives the framework’s bootstrap phase, you can also access configuration values dynamically in your components using standard environment variables if you have mapped them.
import { DolphFactory } from '@dolphjs/dolph';import { AppComponent } from './app.component';
const dolph = new DolphFactory([AppComponent]);
// You can override configuration programmatically before starting// However, using dolph_config.yaml is the recommended approach.dolph.start();