Reference service for serving styles to licit editor
While it can be built and run locally, the project is designed to be run in a docker container.
Name | Default | Description |
---|---|---|
HTTP_PORT | 3000 | Listen port. |
DATA_ROOT | /app/data | Folder where styles.json is stored. |
SAVE_SECONDS | 60 | The number of seconds to wait before saving in-memory data to disk |
REQUESTS_PER_MINUTE | 60 | Configures rate limiting. |
LOG_LEVEL | info | Log level. Other options debug or warn |
# Install build dependencies.
npm ci
# Run all unit tests.
npm test
# Check code style.
npm run lint
# Compile the application.
npm run build
# Run the application.
# This command uses project folder to store styles.json
npm start
A Dockerfile has been included in the project. To create the image run the appropriate docker command or use the supplied npm script
# create the style-service docker image
npm run docker
# Run the docker
docker run -d -p 3000:3000 --name style-service style-service:latest
The above docker command will not persist styles if the container is destroyed. To save your styles map a docker volume to the container folder /app/data
The service exposes the following rest endpoints. See comments in api.ts for additional information. A Postman Collection is included with some sample requests.
Retrieve all styles from the service. See style.ts for more information about a style.
[
{
"styleName": "my-style",
"mode": 1,
"description": "sample style",
"styles": {
"fontSize": "72pt",
...
}
},
...
]
Add a new style or replace an existing style.
{
"styleName": "my-style",
"mode": 1,
"description": "sample style",
"styles": {
"fontSize": "72pt",
...
}
}
{
"statusCode": 200,
"message": "OK",
"location": "/styles/my-style"
}
Gets a single style from the service.
{
"styleName": "my-style",
"mode": 1,
"description": "sample style",
"styles": {
"fontSize": "72pt",
...
}
}
Removes a single style from the service.
204 No Content
Renames an existing style on the service.
{
"oldName": "my-style",
"newName": "my-renamed-style"
}
204 No Content
Adds multiple styles to the service. If replace
is truthy, all styles will be replaced.
{
"replace": false,
"styles": [
{
"styleName": "my-style",
"mode": 1,
"description": "very cool",
"styles": {
"fontSize": "72pt",
...
}
}
]
}
Adds simple status check to service. Returns number of styles.
200 OK
{ size: 999 }