Giter VIP home page Giter VIP logo

dab-swa-library-demo's Introduction

page_type languages products urlFragment name description
sample
azurecli
azstatic-cli
nodejs
javascript
azure
static-web-apps
azure-sql-database
data-api-builder
sample
Jamstack Library App with Azure Static Web Apps, Data API builder, and Azure SQL Database
This sample uses the database connections feature of Azure Static Web Apps to provide CRUD access to database contents with REST, built-in authorizations, and support for database relationships with GraphQL.

Library Demo

A sample app of Static Web Apps with Database connections for a React app and Azure SQL database

Features

This project uses the database connections feature of Static Web Apps to provide the following functionality:

  • CRUD access to database contents with REST or GraphQL
  • Built-in authorization with Static Web Apps authentication
  • Support for database relationships with GraphQL

Getting Started

Prerequisites

  1. An Azure SQL database with the tables created
  2. NodeJS
  3. An Azure Static Web App resource

To get started locally

  1. Clone this repository
  2. Navigate to library directory & open with VSCode
  3. Set the DATABASE_CONNECTION_STRING environment variable to your connection string in your terminal/cmd/powershell. Alternatively, paste your database connection string directly into swa-db-connections/staticwebapp.database.config.json (not recommended) (ensure that you remove this secret from your source code before pushing to GitHub/remote repository)
  4. Run swa start http://localhost:3000 --run "cd library-demo && npm i && npm start" swa-db-connections
    • cd library-demo && npm i && npm start will install needed npm packages and run your React app
    • --data-api-location swa-db-connections indicates to the SWA CLI that your database connections configurations are in the swa-db-connections folder Alternatively, you can start all these projects manually an make use of SWA CLI's other args

You can now use your Static Web App Library Demo Application. It supports authorization, such that anyone logged in with SWA CLI's authentication emulation with the admin role will have CRUD access, while anonymous users are limited to read access. See the configurations detailed in staticwebapp.database.config.json

To deploy

  1. Commit all your changes and push to your repository.
    • You do not need to change your configuration file's data-source object, since this will be overwritten by your Static Web App resource when you connect a database.
    • (If you have paste your connection string directly in your configuration file, ensure that you remove it to avoid making your database connection string public)
  2. Go to your Static Web App resource in the portal. Go to the Database connection tab.
  3. Ensure that your database is ready for connection. It should be configured to accept network requests from Azure services. If you plan to use managed identity as a connection type, ensure that you've configured the managed identity within your database.
  4. Link your database to your default environment. Select your database & enter the credentials.

Troubleshooting

  • Ensure your Azure database is configured to accept network requests
  • Ensure that your configuration files have been placed in your repository and included in your build process.
  • Ensure that your managed identity has been configured within your database.

Screenshots

Home page:

alt text

Non-logged in users receive 403's when they try to Create as configured in swa-db-connections/staticwebapp.database.config.json

alt text

Non-logged in users receive 403's when they try to Delete as configured in swa-db-connections/staticwebapp.database.config.json

alt text

Log in page with admin role

alt text

Non-logged in users receive succesful 201's when they try to Create as configured in swa-db-connections/staticwebapp.database.config.jsonalt text

dab-swa-library-demo's People

Contributors

microsoftopensource avatar thomasgauvin avatar yorek avatar seesharprun avatar

Stargazers

Jonathon Conley avatar lluthus avatar Jonah Andersson avatar Carlos Robles avatar  avatar Neil Camilleri avatar C:\>Marius avatar  avatar Viktor Persson avatar John Bowyer avatar Andrejs Agejevs avatar Dimitri Zilber avatar Stéphane ROKKANEN avatar

Watchers

Erik St. Martin avatar James Cloos avatar Paolo Salvatori avatar Asir Vedamuthu Selvasingh avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

dab-swa-library-demo's Issues

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.