Websites
Nitric provides a simple way to deploy websites to the cloud, allowing you to serve website assets in a serverless environment without managing complex infrastructure.
If you're interested in the architecture, provisioning, or deployment steps, they can be found here.
At this time, websites can only be deployed as static assets. If you require more advanced features, let us know: https://github.com/nitrictech/nitric/issues
Overview
Nitric’s website resource lets you:
- Serve static files (HTML, JS, CSS, images) from cloud storage.
- Serve your entire nitric application from a single domain.
- APIs are automatically served under
/api
and websites are served under/
. - Deploy to various supported providers with minimal configuration.
- Use infrastructure from code to keep your environment consistent.
Enabling Websites
Websites are currently in Preview. To enable this feature in your project add the following to your nitric.yaml
file.
preview:- websites
Create a Website
1. Create your website project
Create a new website project using your preferred framework. For example, using Astro within your nitric project:
npm create astro@latest my-website
2. Add a website resources
Add a website resource to your nitric.yaml
file.
websites:- basedir: ./my-websitebuild:command: npm run buildoutput: ./distdev:command: npm run dev -- --port 4322url: http://localhost:4322
3. Start your website locally
Run nitric start
to start your website locally. This will use the dev
configuration, which proxies requests to your local development server.
Run nitric run
command to run your production website locally. This will use the build
configuration and serve the static files.
4. Deploy your website
Run nitric up
to deploy your website to the cloud.
Sub Sites
You can also configure sub-sites under different paths. These will be deployed as subdirectories of the main site.
Here is an example configuration:
websites:- basedir: ./my-websitebuild:command: npm run buildoutput: ./distdev:command: npm run dev -- --port 4322url: http://localhost:4322# the sub site is served under /docs, ensure you do not have conflicting routes- basedir: ./docs-websitepath: /docsbuild:command: npm run buildoutput: ./distdev:command: npm run dev -- --port 4323url: http://localhost:4323
Configuration
Here is a breakdown of the configuration options:
websites:- # The path to the website project directorybasedir: ./my-website# The path to the website when deployedpath: /# The default file to serve when no file is specifiedindex: index.html# The file to serve when a 404 error occurserror: 404.html# The build options for the websitebuild:# The command to build your websitecommand: npm run build# The output directory for the build commandoutput: ./dist# dev configuration is used by the `nitric start` commanddev:# The command to run your website locallycommand: npm run dev -- --port 4322# The URL to access your website locallyurl: http://localhost:4322
Cloud Service Mapping
Each cloud provider comes with a set of default services used when deploying resources. You can find the default services for each cloud provider below.
If you need support for additional clouds or website types, let us know by opening an issue or joining the conversation on Discord.