Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
47 changes: 46 additions & 1 deletion docs/functions/functions.md
Original file line number Diff line number Diff line change
Expand Up @@ -115,4 +115,49 @@ import { AngularFireFunctionsModule, FUNCTIONS_ORIGIN } from '@angular/fire/func
})
export class AppModule {}

```
```

### Firebase Hosting integration

If you serve your app using [Firebase Hosting](https://firebase.google.com/docs/hosting/), you can configure Functions to be served from the same domain as your app. This will avoid an extra round-trip per function call due to [CORS preflight request](https://developer.mozilla.org/en-US/docs/Glossary/Preflight_request).

To set this up, you first need to update your `hosting` section in `firebase.json` and add one `rewrite` rule per function:

```json
"hosting": {
"rewrites": [
{
"source": "/project-name/us-central1/someFunction",
"function": "someFunction"
},
{
"source": "/project-name/us-central1/anotherFunction",
"function": "anotherFunction"
},
...
]
}
```

Replace `project-name` with your Firebase project id (you can find it by looking at the value of `projectId` field in the Firebase app config). Then deploy your hosting project so that the new settings go into effect.

Next, configure functions origin to point at your app domain:

```ts
import { NgModule } from '@angular/core';
import { AngularFireFunctionsModule, FUNCTIONS_ORIGIN } from '@angular/fire/functions';

@NgModule({
imports: [
...
AngularFireFunctionsModule,
...
],
...
providers: [
{ provide: FUNCTIONS_ORIGIN, useValue: 'https://project-name.web.app' }
]
})
export class AppModule {}

```