A minimalist web app to explore full stack development with a Svelte frontend and Rust backend.
Shows a simple time trending chart for birth names based on this SSA dataset.
See this official SPA + API tutorial.
Breadcrumbs for this process:
read:ssa_stats
permission (see the Axum controller which checks it).Default
role and assign the read:ssa_stats
permission to it.read:ssa_stats
permission.Default
role.
To allow the integration tests to vary the user auth context (so we can test various scenarios), you might also create an M2M / Client-Credentials action like this
exports.onExecuteCredentialsExchange = async (event, api) => {
if (event.client.client_id === event.secrets.clientId) {
const integrationUser = event.request.body['x-integration-user'];
if (!integrationUser) {
api.access.deny('invalid_request', 'x-integration-user field is required.');
return;
}
api.accessToken.setCustomClaim('https://demoapp/email', integrationUser);
}
};
Adding the test user context to the claims simplifies the API code; you could alternatively have the API handle special headers that only apply for tokens associated to the integration testing app.
Create .env
files from both the backend .sample.env and frontend .sample.env, and fill out the placeholders. Note the .env
files are ignored by git as they contain sensitive values.
Start the database
docker compose up database
Apply migrations
cargo run -p database_migrations
Download the SSA Baby Names dataset to the path ./temp/names.zip
, then insert into the database
cargo run -p database_seed
(Optional) Browse the database and confirm data is loaded
docker compose exec database psql -U postgres
Run it all in Docker Compose
docker compose up --build api
Or run the API from the host
docker compose up database otel
cargo run -p backend_axum
Notice that you can access
cd frontend_svelte
npm i
npm run dev --open
Set up Insomnia and import the example collection which demonstrates acquiring an access token as a test user (via the M2M app) and invoking the single controller method. Note some environment variables need to be set from your Auth0 configuration, and secrets can be stored in an Insomnia Vault.