Flarum Framework

repository·2.x·Indexed 27 days ago

https://github.com/flarum/framework

Documentation for the Flarum framework, a lightweight and extensible discussion platform built with PHP and Mithril. Includes guides for core extensions such as GDPR (data exports and PII redaction), the Extension Manager, and Realtime websocket server configuration (including Supervisor and systemd daemon setup). Also provides developer tooling configurations for @flarum/jest-config and @flarum/prettier-config.

Tokens
8.2K
Snippets
24
Records
59
Agent score
92%

What's inside flarum-framework

  1. Use the Extension Manager to manage extensions

    2.x

    The Extension Manager is a tool for installing and managing Flarum extensions directly from the administration interface. It uses Composer to perform installations and updates.

    Security Warning: Granting administrative access to untrustworthy users allows them to install potentially malicious extensions.

    If you prefer to manage extensions manually via the command line, this extension is optional and can be removed.

  2. Configure TypeScript for Flarum Jest tests

    2.x

    If your extension uses TypeScript, you need a specific TypeScript configuration for your tests to ensure proper type resolution. Create a tsconfig.test.json file that extends your base configuration and includes the necessary shims from the @flarum/jest-config package.

    {
      "extends": "./tsconfig.json",
      "include": ["tests/**/*"],
      "files": ["../../../node_modules/@flarum/jest-config/shims.d.ts"]
    }
  3. Configure Jest for Flarum extensions

    2.x

    To use @flarum/jest-config, you must create a jest.config.cjs file in your project root that exports the configuration provided by the package.

    Note: Ensure you have renamed your webpack.config.js to webpack.config.cjs as part of the setup requirements.

    module.exports = require('@flarum/jest-config')();
  4. Set up TypeScript configuration for Flarum extensions

    2.x

    To ensure your IDE provides correct TypeScript support for a Flarum extension, you must install flarum-tsconfig as a development dependency and create a tsconfig.json file in your extension's js folder. This configuration extends Flarum's standard settings and includes core typings for global namespaces like dayjs and $.

    Prerequisites:

    1. Install the package via npm or yarn.
    2. Run composer update in your extension's root directory to ensure Flarum core typings are available in the vendor directory.

    Note: The vendor directory should not be committed to Git.

    # Install the dependency
    npm install --save-dev flarum-tsconfig
    # or
    yarn add --dev flarum-tsconfig
    
    # Create a tsconfig.json in your js folder
    ```jsonc
    {
      "extends": "flarum-tsconfig",
      "include": ["src/**/*", "../vendor/flarum/core/js/dist-typings/@types/**/*"],
      "compilerOptions": {
        "declarationDir": "./dist-typings",
        "paths": {
          "flarum/*": ["../vendor/flarum/core/js/dist-typings/*"]
        }
      }
    }
  5. Install Flarum

    2.x

    This repository contains the core framework code. To set up a functional forum instance, do not use this repository directly. Instead, use the Flarum skeleton repository to get a ready-to-use installation structure.

    https://github.com/flarum/flarum
  6. Extend @flarum/prettier-config with custom options

    2.x

    If you need to override specific settings, do not use the prettier key in package.json. Instead, create a .prettierrc.js file, import the Flarum configuration using require('@flarum/prettier-config'), and spread it into your exported object along with your custom options.

    // .prettierrc.js
    module.exports = {
      ...require("@flarum/prettier-config"),
      semi: false,
    };
  7. Set up Realtime as a daemon with systemd

    2.x

    To run Realtime as a systemd service, create /etc/systemd/system/flarum-realtime.service with the following content (adjusting WorkingDirectory, ExecStart path, and User to match your environment):

    [Unit]
    Description=flarum-realtime
    StartLimitIntervalSec=0
    
    [Service]
    Type=simple
    User=www-data
    WorkingDirectory=/var/www/flarum
    ExecStart=/usr/bin/php flarum realtime:serve
    Restart=always
    RestartSec=5
    
    [Install]
    WantedBy=multi-user.target

    Then run:

    1. sudo systemctl daemon-reload
    2. sudo systemctl start flarum-realtime.service
    3. sudo systemctl enable flarum-realtime.service (to start on boot).
  8. Run Realtime over HTTPS/SSL using Nginx

    2.x

    To run the websocket server encrypted, proxy the port using Nginx. Add the Realtime Nginx include before your Flarum Nginx include at the end of your server block:

    server {
      # your php matching instructions
      
      include /var/www/flarum/vendor/blomstra/realtime/.nginx.conf;
      include /var/www/flarum/.nginx.conf;
    }