This document describes how to build and run the Soundscape Authoring web app.
Soundscape Authoring is a web app which allows users to create routed activities for use with the Soundscape iOS app.
- Azure
- Azure Database for PostgreSQL server
- Storage account
- Azure Maps
- App Service
- B2C Tenant for authentication (using Microsoft account login)
- Backend
- Python
- Django
- Frontend
- JavaScript
- React
- Bootstrap
- IDE
- VSCode
- Azure Account + App Service VSCode extensions
In your Azure account:
- Create a
Resource Group
. - Create a
Storage Account
(for app content, images, GPX files, etc).- Create a blob container named "authoring" with Blob public access level.
- Create an Azure Database for
PostgreSQL Server
(for Django content).- Go to "Connection Security" and in "Allow access to Azure services" select "Yes".
- Create a Database named "authoring". You can use Terminal:
- Go to "Connection Security" and add your IP.
- Go to "Connection Strings" and copy the
psql
string. Default DB ispostgres
. psql "host=host port=port dbname=dbname user=user password=password sslmode=require"
CREATE DATABASE authoring;
\q
- Create a
B2C Tenant
.- Create
App registration
application.- For Platform configuration, add Web and for the redirect URIs use:
<app-url>/.auth/login/aad/callback
. - Put a checkmark next to
ID tokens
. - Save the
Application (client) ID
from the Overview page.
- For Platform configuration, add Web and for the redirect URIs use:
- Create a User Flow with the claims country, display name and object ID.
- Create
- Create an
App Service
with B2 App Service Plan.- Go to
Configuration
and add environment variables (see.env.example
file). - Go to
Authentication
and add theMicrosoft
identity provider. Use the saved client ID from the previous step.
- Go to
- In production, we use
Azure B2C
to authenticate the user. After authentication, we load theURL/.auth/me
resource, which contains a JSON file with access tokens and the needed user ID (objectidentifier
). - In development, we don't have a way to use the B2C authentication flow. Use the following guidance:
- Open the existing production webpage followed by
/.auth/me
. - Download the JSON and store it in
/backend/.auth/me.json
. - At debug, the project will load this file and it will be used as the credentials.
- Important! Make sure to not commit this file to
Git
.
- Open the existing production webpage followed by
The project contains two folders, backend
and frontend
.
- Backend
- To run the project locally, open the
backend
folder in VSCode and run the project (See Backend for more info). - This will make the backend webpage available at the following addresses:
- http://127.0.0.1:8000/ serves the frontend React SPA webpage.
- http://127.0.0.1:8000/api/v1/ serves the Django REST API webpage.
- To run the project locally, open the
- Frontend
- Open the
frontend
folder as a separate VSCode window and run the project (See Frontend for more info). - Running:
- Run the command
npm run start
(or press the run button in the NPM scripts section). - Run via VSCode (F5).
- Access the frontend webpage at http://10.0.0.155:3000/.
- Run the command
- Building:
- When building the frontend project (as opposed to running) it injects the compiled React SPA webpage files into the folder
/backend/frontend/serve
. These are the files that will be served in production and also when viewing http://127.0.0.1:8000/.
- When building the frontend project (as opposed to running) it injects the compiled React SPA webpage files into the folder
- Open the
- In the
/backend
folder, if there is no virtual environment (.venv
), create one and select it as the default Python interpreter in VSCode. Runpython3 -m venv .venv
. - If the Python packages are not installed, run
pip install -r requirements.txt
. - Run:
- python manage.py makemigrations
- python manage.py makemigrations api
- python manage.py migrate
- In the folder
/backend/.env
:- Create the files
local.env
,development.env
andproduction.env
. - Fill in the needed properties as shown in the
example.env
file. You can use the values in theConfiguration
section of the Azure App Service resource.
- Create the files
- Add the auth file as described in the Authentication section.
- Before running, make sure you are running the needed configuration - in the file
/backend/.vscode/lunch.json
, make sure theenvFile
property points to the environment file you are looking to run. - Run via VSCode (F5).
Note that when running in a local
environment, data is stored and retrieved from a local SQLite
file. For development
and production
, the database is a PostgreSQL server.
- Make change to the model objects in the
models.py
file (and other files such asserializers.py
if needed). - Make sure you are running the needed configuration - in the file
/backend/.vscode/lunch.json
, make sure theenvFile
property points to the environment file you are looking to run in. - Run the following lunch schemes:
Django Make Migrations
Django Migrate
Important! Double check before doing this, as this can migrate a production database if the environment property is not set properly in the lunch configurations.
- In the
/frontend
folder, if the NPM packages are not installed, runnpm install
. - Make sure to add the
authentication
file to the backend (See the Authentication section). - Run the command
npm run start
(or press the run button in the NPM scripts section).- Run via VSCode (F5).
- Access the frontend webpage at http://10.0.0.155:3000/.
There is a simple allowlist that only allows specific emails to access the webpage.
This list is managed in the backend app, under the data model UserPermissions
.
In order to view and add emails to the allowlist, do the following:
- In Azure, go to "Connection Security" and add your IP. Add Rule, Start IP and End IP should be the same IPv4 as yours.
- Using a PostgreSQL command-line or GUI, connect to the Azure DB or open the SQLite file if running locally (you can use Azure Data Studio with the PostgreSQL extension).
- Select the table
public.api_userpermissions
. - Add a row with
user_email
and inputtrue
in theallow_app
value.
- You should only deploy the backend folder, as it contains the compiled React frontend files in the
/backend/frontend/serve
folder. - Important! Make sure to build the frontend (React) application before uploading.
- Select the Azure extension in VSCode, select App Service, press the "Deploy to Web App" button and select the App Service destination.
- When complete, wait a couple of minutes and access the webpage to see if the changes are live.