Before deploying to your live site, you'll want to view and test your changes. Firebase Hosting enables you to view and test changes locally and interact with emulated backend project resources. If you need your teammates to view and test your changes, Hosting can create sharable, temporary preview URLs for your site. We even support a GitHub integration to deploy from a pull request.
Before you begin
Complete the steps listed on the Hosting Get Started page , specifically the following tasks:
- Install or update the Firebase CLI to its latest version.
- Connect the local project directory (containing your app's content) to your Firebase project.
You can optionally deploy your app's Hosting content and config, but it's not a prerequisite for the steps on this page.
Step 1:Test locally
If you're making quick iterations or you want your app to interact with emulated backend project resources, you can test your Hosting content and config locally. When testing locally, Firebase serves your web app at a locally hosted URL.
Hosting is part of the Firebase Local Emulator Suite , which enables your app to interact with your emulated Hosting content and config, as well as optionally your emulated project resources (functions, databases, and rules).
-
(Optional) By default, your locally hosted app will interact with real , not emulated , project resources (functions, database, rules, etc.). You can instead optionally connect your app to use any emulated project resources that you've configured. Learn more: Realtime Database | Cloud Firestore | Cloud Functions
-
From the root of your local project directory, run the following command:
firebase emulators:start
-
Open your web app at the local URL returned by the CLI (usually
http://localhost:5000
). -
To update the local URL with changes, refresh your browser.
Test from other local devices
By default, the emulators only respond to requests from localhost
. This
means that you'll be able to access your hosted content from your computer's web
browser but not from other devices on your network. If you'd like to test from
other local devices, configure your firebase.json
like so:
"emulators"
:
{
// ...
"hosting"
:
{
"port"
:
5000
,
"host"
:
"0.0.0.0"
}
}
Test locally using firebase serve
(not recommended)
When using firebase serve
, your app interacts with an emulated
backend for
your Hosting
content and config (and optionally functions) but your real
backend for all other project resources.
-
From the root of your local project directory, run the following command:
firebase serve --only hosting
-
Open your web app at the local URL returned by the CLI (usually
http://localhost:5000
). -
To update the local URL with changes, refresh your browser.
Use firebase serve
to test from other local devices
By default, firebase serve
only responds to requests from localhost
. This
means that you'll be able to access your hosted content from your computer's web
browser but not from other devices on your network. If you'd like to test from
other local devices, use the --host
flag, like so:
firebase serve --host 0.0.0.0 // accepts requests to any host