Home

Awesome

F# Trivia Game

This repository contains an F# trivia game that has been built for Azure Static Web Apps, showing off how you can use Fable for a front end and F# Azure Functions for the backend. Data is then stored in CosmosDB.

You can find a deployed version of the application at https://black-glacier-08edf5f10.azurestaticapps.net/.

Running the app

This repo is designed to be used in a VS Code Remote Container, so you'll need VS Code and Docker installed, the devcontainer will take care of the rest of the dependencies.

You'll need to create a CosmosDB account and a CosmosDB database, with a database named trivia and a collection named game. A sample question dataset can be found at api/trivia.json, which has been exported from Open TriviaDB.

Once your CosmosDB account is created, you'll need to create a local.settings.json file in the api folder to put the connection string for CosmosDB:

{
    "IsEncrypted": false,
    "Values": {
        "AzureWebJobsStorage": "UseDevelopmentStorage=true",
        "FUNCTIONS_WORKER_RUNTIME": "dotnet",
        "CosmosConnection": "YOUR_CONNECTION_STRING_HERE"
    }
}

Note: this file is not part of source control, we don't want secrets on GitHub 😉.

Launch the application with the Launch it all 🚀 VS Code debugger option and navigate to http://localhost:4280 in your browser.

Note: If the site isn't accessible, ensure that the Run emulator command launched the Static Web Apps CLI properly. Sometimes it fails if Fable takes too long to start, so just restart it.

Resources