Illust API

The Firebase Cloud Functions for the Illust marketplace and WebAR sites.

This uses Express/Typescript to set up the cloud functions.

Testing

To run spin up the Firebase emulator, and run all tests:

yarn test

However, it can be faster to run the emulator in a separate terminal, so it doesn't have to spin up every time. To do that, run the following commands in separate terminals:

yarn test:emulator
yarn test:run

This also lets you more easily specify a path to test, like:

yarn test:run src/routes/users.test.ts

Valid user accounts

There is one valid user account set up for testing. Here are the credentials:

Auth Token: good-token User UID: alice

See setupTests.ts for more details.

Configuration

Instead of env vars, firebase cloud functions have their own configuration system. For local development, add values to ./.runtimeconfig.json. For prod and staging, use:

yarn firebase use staging # or prod
yarn firebase functions:config:get # Get the current config
yarn firebase functions:config:set marketplace.varname=Value # Set a new value

Default values are stored in src/defaultConfig.ts

Setting Up An endpoint and collection

  1. Update firebase.json rewrites with source and function name. Wild cards are supported ex:

    { "source": "/pop", "function": "pop" },
    { "source": "/pop/**", "function": "pop" }
  2. Add a route in index.ts. Add a function export in this file. ex:

    import { popApp } from "./routes/pop";
    export const pop = functions.https.onRequest(popApp);
  3. If adding a new collection add it to the shared package and export the interface. ex

    export interface Pop {
      id: string;
      claimer: string;
      tokenId: string;
    }
  4. If adding a new collection add it to the collections.ts file's Firestore class

    // collections.ts
    pops = this.getCollection<Pop>("pops");
    // In API code
    import { fb } from "~/lib/fb";
    
    await fb.db.pops.get();
  5. Verify your route has appropriate CORS settings

    popApp.use(cors(), json());

Last updated