Environment Variables

In the development environment of Screenly Playground, several environment variables can be configured to customize behavior. Environment variables can be set in a .env file at the root of the project.

Example .env file:

# PostgreSQL database settings
DATABASE_URL=postgres://username:password@localhost:5432/screenly_playground

# Redis cache settings
REDIS_URL=redis://localhost:6379

# Flask application settings
FLASK_ENV=development
FLASK_SECRET_KEY=your_secret_key

# Debugging options
DEBUG=True

Python Configuration

The main configuration file for the Python application can be found in the app/config.py. You can modify the settings by importing these environment variables.

Example of config.py:

import os

class Config:
    DATABASE_URL = os.getenv('DATABASE_URL')
    REDIS_URL = os.getenv('REDIS_URL')
    SECRET_KEY = os.getenv('FLASK_SECRET_KEY')
    DEBUG = os.getenv('DEBUG') == 'True'
    
class DevelopmentConfig(Config):
    DEBUG = True
    
config = {
    'development': DevelopmentConfig,
}

Frontend Configuration

The front-end configuration is primarily managed through JavaScript, as settings are often context-dependent.

An example of a configuration in JavaScript to set the API base URL:

const config = {
    apiBaseURL: process.env.API_BASE_URL || 'http://localhost:5000/api',
};

// Usage
fetch(`${config.apiBaseURL}/endpoint`)
    .then(response => response.json())
    .then(data => console.log(data));

Docker Configuration

A Dockerfile is included for creating the development environment, which ensures all dependencies are correctly set.

Example Dockerfile:

FROM python:3.8-slim

# Set working directory
WORKDIR /app

# Copy the requirements file
COPY requirements.txt .

# Install dependencies
RUN pip install --no-cache-dir -r requirements.txt

# Copy the application code
COPY . .

# Command to run the application
CMD ["flask", "run", "--host=0.0.0.0"]

Procfile

In a typical Heroku setup, a Procfile is used to specify the commands that are executed by the app on startup. For a development environment, the command might differ from production.

Example Procfile:

web: python -m flask run

CSS Configuration

The styles are configured using CSS. You may adjust variables in a CSS file, for instance, variables like colors or font-sizes can be defined in a _variables.scss file if using SCSS:

Example _variables.scss:

$primary-color: #3498db;
$secondary-color: #2ecc71;
$font-size: 16px;

Shell Configuration

If using shell scripts for tasks such as starting servers or running migrations, ensure they are executable.

Example start.sh:

#!/bin/bash

# Start the development server
flask run --host=0.0.0.0

# Command to run migrations
flask db upgrade

Enable execution:

chmod +x start.sh

Conclusion

Setting the correct configuration for the development environment in Screenly Playground involves adjusting environment variables, modifying configuration files in both Python and JavaScript, preparing Docker images, and ensuring proper shell scripting for task automation. Each component plays a critical role in offering a seamless development experience, ensuring that the application runs smoothly with the specified configurations.

Source: Source Information for the Configuration