8000 refactor!: remove firebase functions in favor of firebase app hosting by Yuangwang Β· Pull Request #3215 Β· nitrojs/nitro Β· GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

refactor!: remove firebase functions in favor of firebase app hosting #3215

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 9 commits into from
Mar 21, 2025
Merged
Show file tree
Hide file tree
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
1 change: 1 addition & 0 deletions docs/1.guide/00.migration.md
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,7 @@ Some (legacy) presets have been removed or renamed.
| `edgio` | `layer0` |
| `cli` | Removed due to lack of use |
| `service_worker` | Removed due to instability |
| `firebase` | Use new firebase app hosting |

## Removed Subpath Exports

Expand Down
1 change: 1 addition & 0 deletions docs/2.deploy/0.index.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ When deploying to production using CI/CD, Nitro tries to automatically detect th
- [aws amplify](/deploy/providers/aws-amplify)
- [azure](/deploy/providers/azure)
- [cloudflare pages](/deploy/providers/cloudflare#cloudflare-pages)
- [firebase app hosting](/deploy/providers/firebase#firebase-app-hosting)
- [netlify](/deploy/providers/netlify)
- [stormkit](/deploy/providers/stormkit)
- [vercel](/deploy/providers/vercel)
Expand Down
209 changes: 8 additions & 201 deletions docs/2.deploy/20.providers/firebase.md
Original file line number Diff line number Diff line change
@@ -1,19 +1,17 @@
# Firebase

> Deploy Nitro apps to Firebase hosting.
> Deploy Nitro apps to Firebase.

<!--
::note
You will need to be on the [**Blaze plan**](https://firebase.google.com/pricing) (Pay as you go) to get started.
::

## Firebase app hosting <sup>(beta)</sup>
## Firebase app hosting

Preset: `firebase_app_hosting`

:read-more{title="Firebase App Hosting" to="https://firebase.google.com/docs/app-hosting"}

::important
Firebase app hosting support is currently available in the Nitro [nightly release channel](/guide/nightly).
::

::tip
You can integrate with this provider using [zero configuration](/deploy/#zero-config-providers).
::
Expand All @@ -27,198 +25,7 @@ You can integrate with this provider using [zero configuration](/deploy/#zero-co
- Choose a region.
- Import a GitHub repository (you’ll need to link your GitHub account).
- Configure deployment settings (project root directory and branch), and enable automatic rollouts.
- Choose a unique ID for deployment.
4. Wait for the first release to complete.

-->

## Firebase hosting
10000

**Preset:** `firebase`

:read-more{title="Firebase Hosting" to="https://firebase.google.com/docs/hosting"}

> [!NOTE]
> This preset uses [2nd gen](https://firebase.google.com/docs/functions/version-comparison#new-in-2nd-gen) firebase cloud functions

### Project Setup

#### Using firebase CLI (recommended)

You may instead prefer to set up your project with the Firebase CLI, which will fetch your project ID for you, add required dependencies (see above) and even set up automated deployments via GitHub Actions (for hosting only). [Learn about installing the firebase CLI](https://firebase.google.com/docs/cli#windows-npm).

1. Install firebase CLI globally

Always try to use the latest version of the Firebase CLI.

```bash
npm install -g firebase-tools@latest
```

**Note**: You need to be on [^11.18.0](https://github.com/firebase/firebase-tools/releases/tag/v11.18.0) to deploy a `nodejs18` function.

2. Initialize your firebase project

```bash
firebase login
firebase init hosting
```

When prompted, you can enter `.output/public` as the public directory. In the next step, **do not** configure your project as a single-page app.

Once complete, add the following to your `firebase.json` to enable server rendering in Cloud Functions:

```json [firebase.json]
{
"functions": { "source": ".output/server" },
"hosting": [
{
"site": "<your_project_id>",
"public": ".output/public",
"cleanUrls": true,
"rewrites": [{ "source": "**", "function": "server" }]
}
]
}
```

You can find more details in the [Firebase documentation](https://firebase.google.com/docs/hosting/quickstart).

#### Alternative method

If you don't already have a `firebase.json` in your root directory, Nitro will create one the first time you run it. In this file, you will need to replace `<your_project_id>` with the ID of your Firebase project. This file should then be committed to the git.

1. Create a `.firebaserc` file

It is recommended to create a `.firebaserc` file so you don't need to manually pass your project ID to your `firebase` commands (with `--project <your_project_id>`):

```json [.firebaserc]
{
"projects": {
"default": "<your_project_id>"
}
}
```

This file is usually generated when you initialize your project with the Firebase CLI. But if you don't have one, you can create it manually.

2. Install firebase dependencies

Then, add Firebase dependencies to your project:

:pm-install{name="firebase-admin firebase-functions firebase-functions-test" dev}

3. Log into the firebase CLI

Make sure you are authenticated with the firebase cli. Run this command and follow the prompts:

:pm-x{command="firebase-tools login"}
- Choose a unique ID for your backend.
4. Click Finish & Deploy to create your first rollout.

### Local preview

You can preview a local version of your site if you need to test things out without deploying.

```bash
NITRO_PRESET=firebase npm run build
firebase emulators:start
```

### Build and deploy

Deploy to Firebase Hosting by running a Nitro build and then running the `firebase deploy` command.

```bash
NITRO_PRESET=firebase npm run build
```

:pm-x{command="firebase-tools deploy"}

If you installed the Firebase CLI globally, you can also run:

```bash
firebase deploy
```

#### Runtime Node.js version

You can set custom Node.js version in configuration:

::code-group

```ts [nitro.config.ts]
export default defineNitroConfig({
firebase: {
nodeVersion: "20" // Can be "16", "18", "20" or "22"
},
});
```

```ts [nuxt.config.ts]
export default defineNuxtConfig({
nitro: {
firebase: {
nodeVersion: "20" // Can be "16", "18", "20" or "22"
},
},
});
```

::

Firebase tools use the `engines.node` version in `package.json` to determine which node version to use for your functions. Nitro automatically writes to the `.output/server/package.json` with configured Node.js version.

You might also need to add a runtime key to your `firebase.json` file:

```json [firebase.json]
{
"functions": {
"source": ".output/server",
"runtime": "nodejs20"
}
}
```

You can read more about this in [Firebase Docs](https://firebase.google.com/docs/functions/manage-functions?gen=2nd#set_nodejs_version).

### If your firebase project has other cloud functions

You may be warned that other cloud functions will be deleted when you deploy your nitro project. This is because nitro will deploy your entire project to firebase functions. If you want to deploy only your nitro project, you can use the `--only` flag:

```bash
firebase deploy --only functions:server,hosting
```

### Advanced

#### Renaming function

When deploying multiple apps within the same Firebase project, you must give your server a unique name in order to avoid overwriting
your functions.

You can specify a new name for the deployed Firebase function in your configuration:

::code-group

```ts [nitro.config.ts]
export default defineNitroConfig({
firebase: {
serverFunctionName: "<new_function_name>"
}
})
```

```ts [nuxt.config.ts]
export default defineNuxtConfig({
nitro: {
firebase: {
serverFunctionName: "<new_function_name>"
}
}
})
```

::

::important
`firebase.serverFunctionName` must be a valid JS variable name and cannot include dashes (`-`).
::
When you deploy with Firebase App Hosting, the App Hosting preset will be run automatically at build time.
2 changes: 0 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -146,8 +146,6 @@
"eslint-config-unjs": "^0.4.2",
"execa": "^9.5.2",
"expect-type": "^1.2.0",
"firebase-admin": "^12.7.0",
"firebase-functions": "^4.9.0",
"get-port-please": "^3.1.2",
"miniflare": "^4.20250317.0",
"prettier": "^3.5.3",
Expand Down
Loading
0