This template demonstrates building Directus for Platform.sh. It includes a quickstart application configured to run with PostgreSQL. It is intended for you to use as a starting point and modify for your own needs.
Directus is an open-source platform that allows you to create and manage an API from data stored in a database.
- Node.js 12
- PostgreSQL 12
- Redis 6.0
- Automatic TLS certificates
- npm-based build
This template does not require any additional configuration once deployed to start developing your Directus application. During the first deploy, however, an admin user was added to allow you to log in. Those credentials are set (along with many other Platform.sh-specific settings) in the .environment
file:
# Initial admin user on first deploy.
export ADMIN_EMAIL='admin@example.com'
export ADMIN_PASSWORD='password'
After you log in for the first time, be sure to update this password immediately.
Although this project uses PostgreSQL as its primary database, Directus supports a number of other options that can be easily substituted using Platform.sh's managed services.
The Directus CLI is used to create both a role UUID for admin users, and to use that UUID to create the initial admin user. Currently, having a LOG_LEVEL
for Directus other than silent
causes the log message to be included in the following line from the .platform.app.yaml
file's deploy hook, resulting in a syntax error when creating that first user:
ROLE_UUID=$(npx directus roles create --name admin --admin)
This is only something to be aware of on the first install, or when using a similar method for creating new users using the CLI. After you have deployed Directus and created the first admin user, you will likely want to update the .environment
file to set more reasonable environment-dependent log messages:
if [ "$PLATFORM_BRANCH" != "master" ] ; then
export LOG_LEVEL="debug"
else
export LOG_LEVEL="info"
fi
The following files and additions make the framework work on Platform.sh on top of the basic quickstart project (npx create-directus-project
). If using this project as a reference for your own existing project, replicate the changes below to your project.
- The
.platform.app.yaml
,.platform/services.yaml
, and.platform/routes.yaml
files have been added. These provide Platform.sh-specific configuration and are present in all projects on Platform.sh. You may customize them as you see fit. - The
.environment
file provides Platform.sh-specific environment variable overrides from the generated default.env
settings for Directus and PostgreSQL. It also sets an initial username and password for an admin user. On Platform.sh, a.env
file is required to configure Directus but is not committed (see below) in this project. Rather, at build time Directus'sexample.env
file (node_modules/directus/example.env
) is renamed in its place with a set of standard defaults which are then overridden by.environment
. Consult this file locally, and then override with your own settings in.environment
when appropriate. - A
.gitignore
file has been added to preventnode_modules
and your.env
generated for local development from being committed.
-
Add the database
With this configuration, you will need to manually add Directus's database before running locally. For Postgresql:
$ psql psql (12.4) Type "help" for help. me=# create database directus; CREATE DATABASE
-
Set up your database
Run the commands below, and then follow the CLI prompts provided to configure Directus on your local database installation:
$ npm install $ npx directus init
-
Run the server
Run the Directus server locally with the command
npx directus start
.