Skip to main content

Offline Mode

Reforge is intended to be bomb-proof. This means that your servers should happily continue to evaluate feature flags and config, even if, despite our intense efforts, our servers are down. As a developer, you should also be able to run your app and test your code even if you don't have a reliable internet connection. This is why Reforge has an offline mode.

Using Reforge offline

Reforge has Backend and Frontend SDKs, each supporting offline mode using Datafiles. Datafiles are JSON files containing the feature flags and configs you would normally get from the Reforge servers.

You can download the datafile for your project with the Reforge CLI.

You can check this datafile into your source control system, and use it to run your app in offline mode. Be sure to update this datafile periodically to get the latest rulesets from the Reforge servers.

Backend SDKs

Backend SDKs can use Datafiles to run in offline mode. By specifying REFORGE_DATAFILE=./path-to-your-datafile.json in your environment, you can run your app without needing to connect to the Reforge servers. Since the datafile is a complete representation of the payload you'd normally get from reforge.com, your servers will continue to evaluate flags and configs using your complete ruleset (at the time the datafile was generated).

If you're using Ruby on Rails, for example, you can run your server using a datafile like this:

REFORGE_DATAFILE=./path-to-your-datafile.json rails server

Frontend SDKs

Frontend SDKs have two options for offline mode. In both cases, you'll need a datafile.

Using Backend SDK JS stub/bootstrapping

If you're already using one of the Backend SDKs that supports Frontend bootstrapping, you can use the same datafile for your frontend. Sending your evaluations from your backend to your frontend will save your users an HTTP request and allow you to run offline without any changes to your frontend code.

Using the Reforge CLI to Serve a datafile

Using reforge serve with a datafile will start a local server that serves the datafile to your frontend. This is useful if you're not using a Backend SDK that supports bootstrapping, or if you want to run your frontend in isolation. You'll need to update your frontend code to point to wherever your reforge serve is running.

import { reforge } from "@reforge-com/javascript";

const endpoints = [
// If using the reforge serve command locally
"http://localhost:3099",
// If using `reforge serve` on your server
// (perhaps in a Docker image), use the server's URI here
// "https://reforge.your-backend-server/",
];

const options = {
sdkKey: "REFORGE_FRONTEND_SDK_KEY",
endpoints: endpoints,
};

await reforge.init(options);