Getting Started
This section of the documentation (and in fact a lot about Standard Solid) is heavily borrowed from the Community Solid Server. Huge thanks to them for writing great open source code and documentation!
Standard Solid uses the dependency injection framework Components.js to link all its class instances together, and uses Components-Generator.js to automatically generate the necessary description configurations of all classes.
This framework allows developers to configure components in a JSON file. The advantage of this is that changing the configuration of components does not require any changes to the code, as one can just change the default configuration file, or provide a custom configuration file, to alter their application.
More information can be found in the Components.js documentation, but a summarized overview can be found below.
Component files
Components.js requires a .jsonld
component file for every class a developer might want to instantiate. Fortunately, those get generated automatically by Components-Generator.js.
In the Standard Solid repository, calling npm run build
will generate those JSON-LD files in the dist
folder. The generator uses the index.ts
, so new classes always have to be added there or they will not get a component file.
To do this in your application, assuming you've already installed @comake/solid-on-rails
via npm (following the Quick Start guide), do the following:
Install Components-Generator.js:
Add to or change the script commands in your
package.json
to include:Add the reccommended Components.js settings to your
package.json
:Make sure all your Typescript modules are exported from your
index.ts
fileBuild your app and see your
dist
folder fill with your compiled javascript and components.js configurations
Configuration files
Configuration files are how we tell Components.js which classes to instantiate and link together. The default Standard Solid configuration can be found in the config folder. It is advised that you mirror this folder structure in your application.
A single component in such a configuration file might look as follows:
Notice the matching argument names in the corresponding constructor of the App
class:
The important elements here are the following:
"comment"
- A description of this component (optional)."@id"
- A unique identifier of this component, which allows it to be used as parameter values in different places (optional)."@type"
- The class name of the component. This must be a TypeScript class name that is exported viaindex.ts
.
As you can see from the constructor, the other fields are direct mappings from the constructor parameters. initializer
and finalizable
both reference other objects, which we refer to using their identifiers (eg. urn:solid-on-rails:default:Initializer
). Parameters can also be literals like strings and numbers.
Any parameter can be defined using a variable that is set before calling Components.js. These variables are set when starting up the server, based on the command line parameters.
Create your own configuration
You can now create your own configuration file and startup settings for your application. A good place to start is by copying the default configuration and start modifying it.
For more examples on how to configure, checkout the example application build using Standard Solid, and continue reading the Storage, Routes, and Background Jobs guides.
When you're ready, change the start
command in your package.json
to use your config:
Configuring the Server
An easy way to customize your application is by passing parameters to the solid-on-rails
command as shown above. These parameters give you direct access to some commonly used settings:
Parameter name | Default value | Description |
---|---|---|
|
| The TCP port on which the server should listen. |
|
| The base URL used internally to generate URLs. Change this if your server does not run on |
|
| The detail level of logging; useful for debugging problems. Use |
|
| The configuration for the server. |
| false | Enables detailed logging on error output. |
| Path from where Components.js will start its lookup when initializing configurations. | |
| A string that environment variables must start with to be included as parameters of the server. Defaults to an empty string which includes all environment variable. |
Environment variables
As noted about the envVarPrefix
parameter above, the parameters can also be passed through environment variables.
When envVarPrefix
is set (eg. APP_
), a parameter supplied through an environment variable must start with it and will be converted from CAMEL_CASE
to camelCase
.
eg.
APP_BASE_URL
=>--baseUrl
Command-line arguments will always override environment variables!
Last updated