Skip to content

Commit

Permalink
docs(content): requireSync note, ssr root route, app generation, and …
Browse files Browse the repository at this point in the history
…custom URL prefix
  • Loading branch information
leblancmeneses committed Oct 2, 2024
1 parent e866d00 commit ea082fe
Show file tree
Hide file tree
Showing 6 changed files with 95 additions and 22 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@ export const load = async ({
## Injecting the Data

Accessing the data fetched on the server can be done using the `injectLoad` function provided by `@analogjs/router`.
The `load` function here is resolved using Angular route resolvers so `requireSync: false, initialValue: {}` provide no benefit
as `load` is fetched before the component is instantiated.

```ts
// src/app/pages/index.page.ts
Expand Down
43 changes: 26 additions & 17 deletions apps/docs-app/docs/features/deployment/overview.md
Original file line number Diff line number Diff line change
Expand Up @@ -51,37 +51,33 @@ export default defineConfig({

## 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](https://analogjs.org/docs/features/data-fetching/server-side-data-fetching), [html markup and assets](https://angular.io/api/common/APP_BASE_HREF), and [dynamic api routes](https://analogjs.org/docs/features/api/overview) to work correctly on the specified `basehref`.
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](https://analogjs.org/docs/features/data-fetching/server-side-data-fetching), [html markup and assets](https://angular.io/api/common/APP_BASE_HREF), and [dynamic api routes](https://analogjs.org/docs/features/api/overview) to work correctly on the specified `basehref`.

1. Instruct Angular on how recognize and generate URLs. Create a new file `app.config.env.ts`.
1. Update the `app.config.ts` file to use the new file.

This instructs Angular on how recognize and generate URLs.

```ts
import { ApplicationConfig } from '@angular/core';
import { APP_BASE_HREF } from '@angular/common';

export const envConfig: ApplicationConfig = {
providers: [{ provide: APP_BASE_HREF, useValue: '/basehref/' }],
export const appConfig: ApplicationConfig = {
providers: [
[{ provide: APP_BASE_HREF, useValue: import.meta.env.BASE_URL || '/' }],
...
],
};
```

2. Update the `app.config.ts` file to use the new file.

```ts
import { mergeApplicationConfig } from '@angular/core';
import { envConfig } from './app.config.env';

export const appConfig = mergeApplicationConfig(envConfig, {
....
});
```

3. In CI production build

```bash
# 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/
# 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/"
```

4. In production containers specify the env flag `NITRO_APP_BASE_URL`.
Expand All @@ -95,7 +91,20 @@ Given a `vite.config.ts` file similar to this:
```ts
plugins: [
analog({
ssr: true,
apiPrefix: 'api',
nitro: {
routeRules: {
'/': {
prerender: false,
},
},
},
prerender: {
routes: async () => {
return ['/'];
}
}
```
Nitro prefixes all API routes with `/basehref/api`.
36 changes: 36 additions & 0 deletions apps/docs-app/docs/features/deployment/providers.md
Original file line number Diff line number Diff line change
Expand Up @@ -264,6 +264,42 @@ nitro: {
},
```

### Alternatively, multiple AnalogJS projects (/app1, /app2) in a single Firebase Hosting site

This leverages cloud run services to host AnalogJS projects and uses rewrite rules for forwarding traffic from firebase to cloud run.

[Deploying with a custom URL prefix](/docs/features/deployment/overview#deploying-with-a-custom-url-prefix).

```json [firebase.json]
{
"hosting": [
{
"site": "<your_project_id>",
"public": "public",
"cleanUrls": true,
"rewrites": [
{
"source": "/app1",
"run": {
"serviceId": "app1",
"region": "us-central1",
"pinTag": false
}
},
{
"source": "/app1/**",
"run": {
"serviceId": "app1",
"region": "us-central1",
"pinTag": false
}
}
]
}
]
}
```

### Local preview

You can preview a local version of your site to test things out without deploying.
Expand Down
4 changes: 2 additions & 2 deletions apps/docs-app/docs/features/generation/code-generation.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ The Analog plugin for Nx provides a series of generators that help automate some
To generate a new Analog application within an Nx workspace, use the application generator:

```shell
npx nx generate @analogjs/platform:application my-app
npx nx generate @analogjs/platform:app my-app
```

### Generating pages
Expand Down Expand Up @@ -51,7 +51,7 @@ Analog provides a series of schematics that help automate some of the frequent t
To generate a new Analog application within an Angular CLI workspace, use the application schematic:

```shell
npx ng generate @analogjs/platform:application my-app
npx ng generate @analogjs/platform:app my-app
```

### Generating pages
Expand Down
28 changes: 27 additions & 1 deletion apps/docs-app/docs/features/server/server-side-rendering.md
Original file line number Diff line number Diff line change
Expand Up @@ -64,4 +64,30 @@ export default defineConfig(({ mode }) => ({
}));
```

You can opt out of prerendering by passing an empty array of routes.
You can opt out of prerendering by passing an empty array of routes and disabling prerender on the root route.

```js
import { defineConfig } from 'vite';
import analog from '@analogjs/platform';
// https://vitejs.dev/config/
export default defineConfig(({ mode }) => ({
// ...other config
plugins: [
analog({
ssr: true,
nitro: {
routeRules: {
'/': {
prerender: false,
},
},
},
prerender: {
routes: async () => {
return ['/'];
},
},
}),
],
}));
```
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ NX 的 Analog 插件提供了一系列生成器帮助在 NX 的工作区里自
使用应用生成器在 NX 工作区里创建一个新的 Analog 应用:

```shell
npx nx generate @analogjs/platform:application my-app
npx nx generate @analogjs/platform:app my-app
```

### 生成页面
Expand Down Expand Up @@ -51,7 +51,7 @@ Analog 提供了一系列原理图帮助在 Angular CLI 工作区自动化一些
要在 Angular CLI 工作区生成一个新的 Analog 应用程序,使用 application 原理图:

```shell
npx ng generate @analogjs/platform:application my-app
npx ng generate @analogjs/platform:app my-app
```

### 生成页面
Expand Down

0 comments on commit ea082fe

Please sign in to comment.