Fifthtry

Environment Variables

Realm does not have a settings file or such, and relies on environment variables for things that are configurable (and generally believes in making as few things configurable as possible).

Here you will find all the environment variables, their purpose and their default value.

PORT=3000

This is the port on which realm listens on.

We do not prefix this variable because this is what Heroku sends us.

TODO: Also support REALM_PORT (with higher precedence).

DATABASE_URL

This is the database URL, this is passed to diesel’s underlying database driver as is.

TODO: link to sqlite and PostgreSQL related pages to explain how to construct this url.

This is a mandatory parameter and no default value is assumed. Realm starter project sets it to sqlite with hello.db as file path.

Note: This variable doesn’t start with REALM_ because a lot of frameworks support this (eg Django, Diesel).

COOKIE_SECRET

This is used to sign cookies if you are using UserData framework.

TODO: Document UserData and link to it.

TODO: Rename this to REALM_COOKIE_SECRET.

REALM_BASE_URL

A string containing the URL which points to our web application. If this variable is unset, realm assumes that you are working on localhost and all the links will be generated using this URL.

REALM_INDEX=index.html

This is the “index file”, which acts as a template for the HTML that is returned by realm.

Sample index.html. This is also used in case the REALM_INDEX is not set, or if it points to a file that is not present or can not be read.

<!DOCTYPE html>
<html>
    <head>
        <meta charset="utf-8" />
        <title>__realm_title__</title>
        <meta name="viewport" content="width=device-width" />
        <script id="data" type="application/json">

        </script>
        <style>p {margin: 0}</style>
    </head>
    <body>
        __realm_body__
        <div id="main"></div>
        <script src='/static/elm.js'></script>
    </body>
</html>

It has a few special markers: __realm_title__, and __realm_body__, these are replaced with html title, JSON and SSR content respectively.

During development (in non release mode), this file is read on every request, in release mode, it is read when the server starts and is not updated till server starts again.

REALM_WATCHER_DIR=frontend

This is the folder that is watched. If this folder changes, iframe.js file is rebuilt. This is used for auto reloading /storybook/ page.

REALM_WATCHER_DOIT_CMD=doit elm

If the watched directory changes, this is the command that is run to build the latest iframe.js file.

REALM_WATCHER_IFRAME=static/iframe.js

This is the path of generated iframe file. It is generated via the REALM_WATCHER_DOIT_CMD command.

DEBUG_REALM_PAGE

This environment variables value is ignored and we only check if it is set or not. If it is set, some extra debug statements are printed on stdout that tell what file was tried for what realm::Page implementation.

REALM_PURE=user

This activates “pure mode” in realm, which is used to improve performance by storing publicly accessible version of every URL in CDN, showing it first to user, and then replacing it with personalised version.

The value of this environment variable is expected to be the key for “user data” in DATA.config, which is merged into pure version to show proper header etc.

To disable this feature, unset the variable or set it to empty string.

REALM_THREAD_POOL_SIZE=40

Realm uses hyper, an async http framework, but converts it to sync for playing nice with diesel etc. We use a thread pool to achieve this.

Thread pool size can be controlled using this environment variable.

REALM_DB_POOL_SIZE=10

realm::base::pg::connection() and related helpers use r2d2 for database connection pooling. The database pool size can be controlled using this environment variable.

REALM_ALLOWED_SB_REFERERS

Realm stories can be embedded in IFrames to be viewed in the realm project. As a security measure, the /storybook/ route returns the stories only if the referer in the request matches the referers specified by this environment variable.

The URLs have to be separated by ,.

Table Of Content

What is Realm?

A Bit On Motivation

Routing is Hard

What does Realm do?

Backend Data And Type Safety

Tutorial

Quick Start Realm Tutorial

In Depth Tutorial (not ready)

Nix
Shell
Doit
Hello Rust
Hello Elm
Hello Static Files
Hello Server Side Rendering
Pre-Commit Hooks

Routing, Request And Response

Frontend, Data, Navigation, And APIs

How To Guides

File Upload

Backend: S3 File Upload
Authenticated File Serving
Frontend: Uploading Files From Elm

How to use storybook?

How to implement “loading..”?

Docs

Realm.In

Realm.Storybook.Story

realm::In

realm::Context

realm::Result

realm.magicSlice

realm::RequestConfig

Environment Variables

Internals - Only for Realm Developers, not Users

“Realm DATA”
iFrame Controller
Shutdown Routine
Testing Internals

Change Log

Get Realm Starter Working

Transparent Offline Feature

How to make http requests in Realm?

Development

Tutorial: ToDo App

Realm Testing

Enhance Realm Starter

Double Load Issue

Deploy To Heroku Button

End failure

Realm-Starter Github Template

Proposal: Tracker And Visit

Proposal: Activity Store

Proposal: Bundling

Proposal: Retry On Network Error

Storybook: Editable JSON

Storybook: Notes

Storybook: Reference

Backlog

Readings

Change Log

How to Publish

Testing

Code Snippets

Skip rustfmt For Some Section

Close Modal Dialog When Clicked Outside

Ignoring Lints In Python

Ignoring Lints (clippy and rustc warnings) In Rust

Handle DateTime in Rust & Elm

Handle CiText value read in Rust

Transport Enum Type to and fro Rust/Elm through JSON