Fragno

Services

Running functions defined by Fragments on the server.

Edit on GitHub

Services are functions exposed by Fragment authors to users. They are designed to be called on the server, such as in loader functions or background processing.

Basic Usage

The services object is available on the Fragment's server-side instance.

jobs/my-background-process.ts
import { createExampleFragmentInstance } from "../lib/example-fragment-server";

export async function myBackgroundProcess() {
  const { getHashFromHostsFileData } = createExampleFragmentInstance().services;

  setInterval(
    () => {
      const hash = getHashFromHostsFileData();
      console.log("Hash of hosts file:", hash);
    },
    /* every hour */ 1000 * 60 * 60,
  );
}

On this page