Deployment
Node.js deployment is the default Analog output preset for production builds.
When running npm run build
with the default preset, the result will be an entry point that launches a ready-to-run Node server.
To start up the standalone server, run:
$ node dist/analog/server/index.mjs
Listening on http://localhost:3000
Environment Variables
You can customize server behavior using following environment variables:
NITRO_PORT
orPORT
(defaults to3000
)NITRO_HOST
orHOST
Built-in Presets
Analog can generate different output formats suitable for different hosting providers from the same code base, you can change the deploy preset using an environment variable or vite.config.ts
.
Using environment variable is recommended for deployments depending on CI/CD.
Example: Using BUILD_PRESET
BUILD_PRESET=node-server
Example: Using vite.config.ts
import { defineConfig } from 'vite';
export default defineConfig({
plugins: [
analog({
nitro: {
preset: 'node-server',
},
}),
],
});
Deploying with a Custom URL Prefix
If you are deploying with a custom URL prefix, such as https://domain.com/ basehref
you must do these steps for server-side-data-fetching, html markup and assets, and dynamic api routes to work correctly on the specified basehref
.
- Update the
app.config.ts
file.
This instructs Angular on how recognize and generate URLs.
import { ApplicationConfig } from '@angular/core';
import { APP_BASE_HREF } from '@angular/common';
export const appConfig: ApplicationConfig = {
providers: [
[{ provide: APP_BASE_HREF, useValue: import.meta.env.BASE_URL || '/' }],
...
],
};
- In CI production build
# sets the base url for server-side data fetching
export VITE_ANALOG_PUBLIC_BASE_URL="https://domain.com/basehref"
# Prefixes all assets and html with /basehref/
# if using nx:
npx nx run appname:build:production --baseHref='/basehref/'
# if using angular build directly:
npx ng build --baseHref="/basehref/"
- In production containers specify the env flag
NITRO_APP_BASE_URL
.
NITRO_APP_BASE_URL="/basehref/"
Given a vite.config.ts
file similar to this:
plugins: [
analog({
apiPrefix: 'api',
nitro: {
routeRules: {
'/': {
prerender: false,
},
},
},
prerender: {
routes: async () => {
return ['/'];
}
}
Nitro prefixes all API routes with /basehref/api
.