Websites
1. System Context
Developers use Nitric to define required websites within their application.
- App code uses the Website resource defined in
nitric.yaml
to specify the websites and their configurations. - Developers can configure base path, index pages, error pages, and other settings in their
nitric.yaml
file. - When a website is defined, a single CDN endpoint is automatically created to serve the website content globally, including APIs as proxies.
Operations use default or overridden IaC (e.g., Terraform modules) to provision the necessary resources for their target cloud.
Example AWS Provider
- AWS S3 serves as the storage backend for static files (e.g., HTML, CSS, JS, images).
- AWS CloudFront is used to distribute the website globally and serve as a single entry point for the whole application.
- AWS IAM providers roles for access to the Website bucket
Example Azure Provider
- Static Website in Azure Blob Storage serves as the storage backend for static files (e.g., HTML, CSS, JS, images).
- Azure Front Door is used to distribute the website globally and serve as a single entry point for the whole application.
2. Sequence
Build Sequence
Below is the sequence of events that occur when a developer registers a website with Nitric:
3. Component
Website Module
- Deploys website assets to a cloud-based storage solution for flexible and scalable hosting.
- Configures a distribution layer to serve the site globally, rewriting API endpoints to
/api/{apiName}
for consistent routing. - Automatically invalidates the cache based on file changes, ensuring users always receive the latest content.
4. Code
Developers write yaml configuration to define the website and implement logic to serve static files.
Nitric website configuration - nitric.yaml
name: service-nameservices:- match: ./services/*.jsstart: npm run dev:services $SERVICE_PATHruntime: noderuntimes:node:dockerfile: ./node.dockerfileargs: {}# The website configurationwebsites:- basedir: ./my-websiteindex: index.htmlerror: 404.htmlbuild:command: npm run buildoutput: ./distdev:command: npm run dev -- --port 4322url: http://localhost:4322
Access an API from the website frontend
async function fetchData() {// due to apis being served from the same domain thanks to rewrites, no CORS is requiredconst response = await fetch('/api/main/hello')const data = await response.json()console.log(data)}
Operations will use or extend the Nitric infrastructure modules, including both Terraform and Pulumi:
- Terraform Modules:
- Not yet available
- Pulumi Modules:
Last updated on Mar 5, 2025