/todo-vanillajs

Primary LanguageHTMLMIT No AttributionMIT-0

A Simple Todo App with Fauna

Note
This repository contains unofficial patterns, sample code, or tools to help developers build more effectively with Fauna. All Fauna Labs repositories are provided "as-is" and without support. By using this repository or its contents, you agree that this repository may never be officially supported and moved to the Fauna organization.

This repo contains a single-page HTML file with embedded JavaScript that implements a simple web-based todo application.

The embedded JavaScript automatically creates a Todos collection and then shows any available todos. Use the input field to create a new todo. For listed todos, you can toggle their done state or delete them.

Each action triggers a Fauna query that creates, updates, or deletes a todo document, respectively.

Important

This code is provided for educational purposes. It is simple and it works.

However, embedding database secrets into HTML would be considered bad practice for production applications, and you should never do this.

Dependencies

  • A Fauna secret, which authorizes queries for a specific database. To acquire a secret:

    1. Log into the Fauna Dashboard. Sign up if you do not already have an account (it’s free!).

    2. Select, or create, a database.

    3. In the Security section, create a new key with the "admin" role. A secret is shown. Copy that to a safe place; a secret is only displayed once.

  • Fauna JavaScript driver: This is fetched from a CDN (you need an internet connection).

  • http-server: A Node.js web server so you can view the todo app locally.

Note that once you create a todo, you can visit the Fauna Dashboard and navigate to the database associated with the secret, and view the "Todos" collection to see the todos. You can manage todo documents in the Dashboard; when you refresh the app, you’ll see the changes.

Usage

  1. Clone this repo.

  2. Enter the clone’s directory.

  3. Run npm i to install http-server.

  4. Edit the index.html file and on line 25, replace the YOUR_FAUNA_SECRET text with your Fauna secret, then save the file.

  5. Below YOUR_FAUNA_SECRET that you just updated, edit the domain option to match the regiion your DB is contained.

    • For example:

      • US region group: db.us.fauna.com

      • EU region group: db.eu.fauna.com

      • Classic region group: db.fauna.com

      • Preview: db.fauna-preview.com

  6. Run npm run serve to start http-server and view the application in your web browser.

Copyright Fauna, Inc. or its affiliates. All rights reserved. SPDX-License-Identifier: MIT-0