You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
You can test your integration locally by following these steps:
63
63
64
-
1. Run `firebase serve` from the terminal. This should build your Angular app and serve it using the Firebase CLI.
65
-
2. Open your web app at the local URL returned by the CLI (usually http://localhost:5000)
64
+
1. Run `firebase serve` from the terminal. This should build your app and serve it using the Firebase CLI.
65
+
2. Open your web app at the local URL returned by the CLI (usually http://localhost:5000).
66
66
67
67
## Deploy your app to Firebase Hosting
68
68
69
-
When you're ready to share your changes with the world, deploy your Angular app to your live site:
69
+
When you're ready to share your changes with the world, deploy your app to your live site:
70
70
71
71
1. Run `firebase deploy` from the terminal.
72
-
2. Check your website on: `SITE_ID.web.app` or `PROJECT_ID.web.app` (or your custom domain, if you did setup one)
72
+
2. Check your website on: `SITE_ID.web.app` or `PROJECT_ID.web.app` (or your custom domain, if you set one up)
73
73
74
-
## "Integrate Angular"
74
+
## Integrate Angular
75
75
76
76
Easily deploy your Angular application to Firebase and serve dynamic content to your users.
77
77
@@ -88,14 +88,14 @@ or modify `firebase.json` for an existing project.
88
88
89
89
#### Initialize a new project
90
90
91
-
1. Run the initialization command from the CLI: ``
91
+
1. Run the initialization command from the CLI:
92
92
93
93
```shell
94
94
firebase init hosting
95
95
```
96
96
97
-
1. Choose your hosting source directory; this could be an existing Angular App
98
-
1. Choose "Dynamic web hosting with web framework"
97
+
1. Choose your hosting source directory; this could be an existing Angular app.
98
+
1. Choose "Dynamic web hosting with web framework."
99
99
1. Choose Angular.
100
100
101
101
#### Initialize an existing project
@@ -118,7 +118,7 @@ After initializing Firebase, you can serve static content with the standard depl
118
118
firebase deploy
119
119
```
120
120
121
-
## Pre-render dynamic content
121
+
###Pre-render dynamic content
122
122
123
123
To prerender dynamic content in Angular, you need to set up Angular Universal. The Firebase CLI expects Express Engine:
124
124
@@ -128,10 +128,10 @@ ng add @nguniversal/express-engine
128
128
129
129
[See the Angular Universal guide for more information.](https://angular.io/guide/universal)
130
130
131
-
### Add prerender URLs
131
+
####Add prerender URLs
132
132
133
-
By default, only the root directory will be prerendered, you can add additional routes by locating the prerender step in
134
-
your angular.json and adding more routes:
133
+
By default, only the root directory will be prerendered. You can add additional routes by locating the prerender step in
134
+
`angular.json` and adding more routes:
135
135
136
136
```json
137
137
{
@@ -152,12 +152,12 @@ your angular.json and adding more routes:
152
152
}
153
153
```
154
154
155
-
Firebase will also respect guessRoutes or a routes.txt file in the hosting root, if you need to customize further.
155
+
Firebase also respects `guessRoutes` or a `routes.txt` file in the hosting root, if you need to customize further.
156
156
See [Angular’s prerendering guide](https://angular.io/guide/prerendering) for more information on those options.
157
157
158
-
### Optional: add a server module
158
+
####Optional: add a server module
159
159
160
-
### Deploy
160
+
####Deploy
161
161
162
162
When you deploy with `firebase deploy`, Firebase builds your browser bundle, your server bundle, and prerenders the
163
163
application. These elements are deployed to Hosting and Cloud Functions.
@@ -167,8 +167,8 @@ application. These elements are deployed to Hosting and Cloud Functions.
167
167
The Firebase CLI assumes that you have server, build, and prerender steps in your schematics with a production
168
168
configuration.
169
169
170
-
If you want to tailor the CLI's assumptions, configure ng deploy and alter the configuration in your angular.json. For
171
-
example, you could disable SSR and serve pre-rendered content exclusively by removing serverTarget:
170
+
If you want to tailor the CLI's assumptions, configure ng deploy and alter the configuration in `angular.json`. For
171
+
example, you could disable SSR and serve pre-rendered content exclusively by removing `serverTarget`:
172
172
173
173
```json
174
174
{
@@ -185,7 +185,7 @@ example, you could disable SSR and serve pre-rendered content exclusively by rem
185
185
186
186
### Optional: integrate with the Firebase JS SDK
187
187
188
-
When including Firebase JS SDK methods in both server and client bundles, guard against runtime errors by checking isSupported() before using the product. [Not all products are supported in all environments.](https://firebase.google.com/docs/web/environments-js-sdk#other_environments)
188
+
When including Firebase JS SDK methods in both server and client bundles, guard against runtime errors by checking `isSupported()` before using the product. [Not all products are supported in all environments.](https://firebase.google.com/docs/web/environments-js-sdk#other_environments)
189
189
190
190
Hint: consider using AngularFire, which does this for you automatically.
191
191
@@ -226,22 +226,22 @@ export const FIREBASE_ADMIN = new InjectionToken<app.App>('firebase-admin');
226
226
227
227
```
228
228
229
-
## Serve fully dynamic content with SSR—Server Side Rendering
229
+
###Serve fully dynamic content with SSR
230
230
231
-
### Optional: integrate with Firebase Authentication
231
+
####Optional: integrate with Firebase Authentication
232
232
233
233
The web framework-aware Firebase deployment tooling automatically keeps client and server state in sync using cookies. The Express `res.locals` object will optionally contain an authenticated Firebase App instance (`firebaseApp`) and the currently signed in user (`currentUser`). This can be injected into your module via the REQUEST token (exported from @nguniversal/express-engine/tokens).
234
234
235
235
236
236
## Integrate Next.js
237
237
238
-
Using the Firebase CLI, you can deploy your next.js Web apps to Firebase and serve them with Firebase Hosting. The CLI respects your next.js settings and translates them to Firebase settings with zero or minimal extra configuration on your part. If your app includes dynamic server-side logic, the CLI deploys that logic to Cloud Functions for Firebase.
238
+
Using the Firebase CLI, you can deploy your Next.js Web apps to Firebase and serve them with Firebase Hosting. The CLI respects your Next.js settings and translates them to Firebase settings with zero or minimal extra configuration on your part. If your app includes dynamic server-side logic, the CLI deploys that logic to Cloud Functions for Firebase.
239
239
240
240
Note: Apps with dynamic server-side logic must provide a billing instrument during Cloud Functions setup. Also note that all frameworks-based functionality provided by the Firebase CLI is currently has experimental status, and may change in backward-incompatible ways.
241
241
242
242
### Before you begin
243
243
244
-
Before you get started deploying your next.js app to Firebase, first review the following requirements and options:
244
+
Before you get started deploying your Next.js app to Firebase, first review the following requirements and options:
245
245
246
246
- All projects must use firebase-tools 10.8 or higher
247
247
- If your project requires SSR, you must provide a billing instrument
@@ -273,9 +273,9 @@ You can [view your deployed app](https://firebase.google.com/docs/hosting/test-p
273
273
274
274
The Firebase CLI will detect usage of [getStaticProps](https://nextjs.org/docs/basic-features/data-fetching/get-static-props) and [getStaticPaths](https://nextjs.org/docs/basic-features/data-fetching/get-static-paths).
275
275
276
-
#### Optional: integrate with Firebase JS SD
276
+
#### Optional: integrate with Firebase JS SDK
277
277
278
-
When including Firebase JS SDK methods in both server and client bundles, guard against runtime errors by checking isSupported() before using the product. [Not all products are supported in all environments.](https://firebase.google.com/docs/web/environments-js-sdk#other_environments)
278
+
When including Firebase JS SDK methods in both server and client bundles, guard against runtime errors by checking `isSupported()` before using the product. [Not all products are supported in all environments.](https://firebase.google.com/docs/web/environments-js-sdk#other_environments)
279
279
280
280
Tip: consider using ReactFire, which does this for you automatically.
281
281
@@ -287,7 +287,7 @@ Admin SDK bundles will fail if included in your browser build; refer to them on
287
287
288
288
The Firebase CLI will detect usage of [getServerSideProps](https://nextjs.org/docs/basic-features/data-fetching/get-server-side-props).
289
289
290
-
### Configure Hosting behavior with next.config.js
290
+
### Configure Hosting behavior with `next.config.js`
291
291
292
292
#### Image Optimization
293
293
@@ -297,7 +297,7 @@ Note: Because of this, Image Optimization and Hosting Preview Channels don’t i
297
297
298
298
#### Redirects, Rewrites, and Headers
299
299
300
-
Firebase CLI will respect [redirects](https://nextjs.org/docs/api-reference/next.config.js/redirects), [rewrites](https://nextjs.org/docs/api-reference/next.config.js/rewrites), and [headers](https://nextjs.org/docs/api-reference/next.config.js/headers) in your next.config.js, converting them to their respective equivalent Firebase Hosting configuration at deploy time.
300
+
Firebase CLI respects [redirects](https://nextjs.org/docs/api-reference/next.config.js/redirects), [rewrites](https://nextjs.org/docs/api-reference/next.config.js/rewrites), and [headers](https://nextjs.org/docs/api-reference/next.config.js/headers) in `next.config.js`, converting them to their respective equivalent Firebase Hosting configuration at deploy time.
301
301
302
302
If a Next.js redirect, rewrite, or header cannot be converted to an equivalent Firebase Hosting header, it falls back and builds a Cloud Function—even if you aren’t using Image Optimization or SSR.
303
303
@@ -306,7 +306,7 @@ If a Next.js redirect, rewrite, or header cannot be converted to an equivalent F
306
306
The web framework-aware Firebase deployment tooling will automatically keep client and server state in sync using cookies. There are some methods provided for accessing the authentication context in SSR:
307
307
308
308
* The Express `res.locals` object will optionally contain an authenticated Firebase App instance (`firebaseApp`) and the currently signed in user (`currentUser`). This can be accessed in `getServerSideProps`.
309
-
* The authenticated Firebase App name is provided on the route query (__firebaseAppName), this allows for manual integration while in context:
309
+
* The authenticated Firebase App name is provided on the route query (`__firebaseAppName`). This allows for manual integration while in context:
310
310
311
311
```typescript
312
312
// get the authenticated Firebase App
@@ -315,7 +315,7 @@ The web framework-aware Firebase deployment tooling will automatically keep clie
315
315
316
316
## Integrate other frameworks with Express.js
317
317
318
-
With some additional configuration, you can build on the basic CLI functionality to extend integration support to Frameworks other than Angular and next.js.
318
+
With some additional configuration, you can build on the basic CLI functionality to extend integration support to Frameworks other than Angular and Next.js.
319
319
320
320
### What you’ll need before you begin
321
321
@@ -331,10 +331,6 @@ or modify `firebase.json` for an existing project.
331
331
332
332
#### Initialize a new project
333
333
334
-
Run the initialization command from the CLI:
335
-
```shell firebase init hosting
336
-
```
337
-
338
334
1. Run the initialization command from the CLI:
339
335
```shell
340
336
firebase init hosting
@@ -360,7 +356,7 @@ Change your hosting config in firebase.json to have a `source` option, rather th
360
356
361
357
#### Configure
362
358
363
-
In order to know how to deploy your application,The Firebase CLI needs to be able to both build your app and known where your tooling places the assets destined for Hosting. This is accomplished with the NPM build script and CJS directories directive in your package.json.
359
+
In order to know how to deploy your application, the Firebase CLI needs to be able to both build your app and know where your tooling places the assets destined for Hosting. This is accomplished with the NPM build script and CJS directories directive in `package.json`.
364
360
365
361
Given the following package.json:
366
362
@@ -377,7 +373,7 @@ Given the following package.json:
377
373
}
378
374
```
379
375
380
-
Firebase CLI only calls your build script, so you’ll need to ensure that your build script is exhaustive.
376
+
The Firebase CLI only calls your build script, so you’ll need to ensure that your build script is exhaustive.
381
377
382
378
Hint: you can add additional steps using &&. If you have a lot of steps consider a shell script or tooling like [npm-run-all](https://www.npmjs.com/package/npm-run-all) or [wireit](https://www.npmjs.com/package/wireit).
383
379
@@ -394,9 +390,9 @@ Hint: you can add additional steps using &&. If you have a lot of steps consider
394
390
}
395
391
```
396
392
397
-
If your framework doesn’t support pre-rendering out-of-box, consider using a tool like [Rendertron](https://github.com/GoogleChrome/rendertron). Rendertron will allow you to make headless Chrome requests against a local instance of your app, so you can save the resulting HTML to be served on Hosting.
393
+
If your framework doesn’t support pre-rendering out of the box, consider using a tool like [Rendertron](https://github.com/GoogleChrome/rendertron). Rendertron will allow you to make headless Chrome requests against a local instance of your app, so you can save the resulting HTML to be served on Hosting.
398
394
399
-
Finally, different frameworks and build tools store their artifacts in different places. Use directories.serve to tell the CLI where your build script is outputting the resulting artifacts:
395
+
Finally, different frameworks and build tools store their artifacts in different places. Use `directories.serve` to tell the CLI where your build script is outputting the resulting artifacts:
400
396
401
397
```json
402
398
{
@@ -422,11 +418,11 @@ firebase deploy
422
418
423
419
Your application should now be configured as an SPA and deployed to Firebase Hosting.
424
420
425
-
####Serve Dynamic Content
421
+
### Serve Dynamic Content
426
422
427
-
To serve up your Express app on Cloud Functions, ensure that your Express app (or express-style url handler) is exported in such a way that Firebase can find it after your library has been NPM packed.
423
+
To serve up your Express app on Cloud Functions, ensure that your Express app (or express-style URL handler) is exported in such a way that Firebase can find it after your library has been NPM packed.
428
424
429
-
To accomplish this, ensure that your files directive includes everything needed for the server and your main entry-point is setup correctly in your package.json:
425
+
To accomplish this, ensure that your files directive includes everything needed for the server and your main entrypoint is set up correctly in `package.json`:
430
426
431
427
```json
432
428
{
@@ -446,7 +442,7 @@ To accomplish this, ensure that your files directive includes everything needed
446
442
}
447
443
```
448
444
449
-
Export your express app from a function named app:
445
+
Export your express app from a function named `app`:
450
446
451
447
```js
452
448
// server.js
@@ -457,7 +453,7 @@ export function app() {
457
453
}
458
454
```
459
455
460
-
Or if you’d rather export an express-style URL handler, name it handle:
456
+
Or if you’d rather export an express-style URL handler, name it `handle`:
461
457
462
458
```js
463
459
exportfunctionhandle(req, res) {
@@ -472,22 +468,10 @@ firebase deploy
472
468
```
473
469
474
470
Your application should now deploy your static content to Firebase Hosting and fall back to your Express app hosted on Cloud Functions.
475
-
Optional: integrate with Firebase Authentication
476
-
The web framework aware Firebase deploy tooling will automatically keep client & server state in sync using cookies. To access the authentication context, the Express `res.locals` object optionally contains an authenticated Firebase App instance (`firebaseApp`) and the currently signed in User (`currentUser`).
477
-
478
-
### Serve locally
479
471
480
-
You can test your integration locally by following these steps:
481
-
482
-
1. Run `firebase serve` from the terminal. This should build your Next.js app and serve it using the Firebase CLI.
483
-
2. Open your web app at the local URL returned by the CLI (usually http://localhost:5000)
484
-
485
-
### Deploy your app to Firebase Hosting
486
-
487
-
When you're ready to share your changes with the world, deploy your Next.js app to your live site:
472
+
### Optional: integrate with Firebase Authentication
488
473
489
-
1. Run `firebase deploy` from the terminal.
490
-
2. Check your website on: `SITE_ID.web.app` or `PROJECT_ID.web.app` (or your custom domain, if you did setup one)
474
+
The web framework-aware Firebase deploy tooling will automatically keep client and server state in sync using cookies. To access the authentication context, the Express `res.locals` object optionally contains an authenticated Firebase App instance (`firebaseApp`) and the currently signed in User (`currentUser`).
0 commit comments