همچنین باید با ویژگی ها و گردش کار پیاده سازی برای Firebase Hosting آشنا باشید. با مقدمه ای برای Firebase Hosting شروع کنید.
با شبیه ساز Firebase Hosting چه کاری می توانم انجام دهم؟
شبیهساز Firebase Hosting شبیهسازی محلی خدمات Hosting با کیفیت بالا را ارائه میکند و بسیاری از عملکردهای موجود در Hosting تولید را ارائه میدهد. شبیه ساز Hosting به شما اجازه می دهد:
نمونه اولیه سایت ها و برنامه های وب استاتیک خود را بدون هزینه های ذخیره سازی یا دسترسی ایجاد کنید
قبل از استقرار در سایت میزبانی خود، توابع HTTPS را نمونه اولیه، آزمایش و اشکال زدایی کنید
سایتها و برنامههای وب را در جریانهای کاری یکپارچهسازی مستمر و کانتینری آزمایش کنید.
یک پروژه Firebase را انتخاب کنید
Firebase Local Emulator Suite محصولات را برای یک پروژه Firebase تقلید می کند.
برای انتخاب پروژه مورد استفاده، قبل از شروع شبیه سازها، در CLI از firebase use . یا، می توانید پرچم --project را به هر فرمان شبیه ساز ارسال کنید.
Local Emulator Suite از شبیه سازی پروژه های Firebase واقعی و پروژه های آزمایشی پشتیبانی می کند.
نوع پروژه
ویژگی ها
با شبیه سازها استفاده کنید
واقعی
یک پروژه Firebase واقعی پروژه ای است که شما ایجاد و پیکربندی کرده اید (به احتمال زیاد از طریق کنسول Firebase ).
پروژه های واقعی دارای منابع زنده هستند، مانند نمونه های پایگاه داده، سطل های ذخیره سازی، توابع یا هر منبع دیگری که برای آن پروژه Firebase تنظیم کرده اید.
هنگام کار با پروژه های Firebase واقعی، می توانید شبیه سازها را برای هر یک یا همه محصولات پشتیبانی شده اجرا کنید.
برای هر محصولی که شبیهسازی نمیکنید، برنامهها و کد شما با منبع زنده (نمونه پایگاه داده، سطل ذخیرهسازی، عملکرد و غیره) تعامل خواهند داشت.
نسخه ی نمایشی
یک پروژه Firebase آزمایشی هیچ پیکربندی Firebase واقعی و هیچ منبع زنده ای ندارد. این پروژه ها معمولاً از طریق نرم افزارهای کد یا آموزش های دیگر قابل دسترسی هستند.
شناسه های پروژه برای پروژه های نمایشی دارای پیشوند demo- هستند.
هنگام کار با پروژه های Firebase آزمایشی، برنامه ها و کد شما فقط با شبیه سازها تعامل دارند. اگر برنامه شما سعی کند با منبعی که شبیه ساز برای آن اجرا نمی شود تعامل داشته باشد، آن کد با شکست مواجه می شود.
توصیه می کنیم تا جایی که امکان دارد از پروژه های نمایشی استفاده کنید. مزایا عبارتند از:
راه اندازی آسان تر، زیرا می توانید شبیه سازها را بدون ایجاد پروژه Firebase اجرا کنید
ایمنی قوی تر، زیرا اگر کد شما به طور تصادفی منابع غیر شبیه سازی شده (تولید) را فراخوانی کند، هیچ شانسی برای تغییر داده ها، استفاده و صورتحساب وجود ندارد.
پشتیبانی آفلاین بهتر است، زیرا برای دانلود پیکربندی SDK نیازی به دسترسی به اینترنت نیست.
گردش کار نمونه سازی اصلی
اگر تکرارهای سریع انجام می دهید یا می خواهید برنامه شما با منابع پروژه باطن شبیه سازی شده تعامل داشته باشد، می توانید محتوای Hosting و پیکربندی محلی خود را آزمایش کنید. هنگام آزمایش محلی، Firebase برنامه وب شما را در یک URL میزبانی محلی ارائه میکند.
(اختیاری) به طور پیش فرض، برنامه میزبانی شده محلی شما با منابع پروژه واقعی ، غیر شبیه سازی شده (توابع، پایگاه داده، قوانین و غیره) تعامل خواهد داشت. در عوض میتوانید بهصورت اختیاری برنامهتان را برای استفاده از منابع پروژه شبیهسازیشدهای که پیکربندی کردهاید، متصل کنید. بیشتر بدانید: Realtime Database | Cloud Firestore | Cloud Functions
از ریشه دایرکتوری پروژه محلی خود، دستور زیر را اجرا کنید:
firebase emulators:start
برنامه وب خود را در URL محلی بازگردانده شده توسط CLI (معمولاً http://localhost:5000 ) باز کنید.
برای به روز رسانی URL محلی با تغییرات، مرورگر خود را بازخوانی کنید.
تست از دستگاه های محلی دیگر
به طور پیش فرض، شبیه سازها فقط به درخواست های localhost پاسخ می دهند. این بدان معنی است که شما می توانید از مرورگر وب رایانه خود به محتوای میزبانی شده خود دسترسی داشته باشید اما از سایر دستگاه های موجود در شبکه خود دسترسی ندارید. اگر میخواهید از دستگاههای محلی دیگر تست کنید، firebase.json خود را به این صورت پیکربندی کنید:
توکنهای تأیید اعتبار برای گردشهای کاری یکپارچهسازی مداوم ایجاد کنید
اگر گردش کار یکپارچه سازی مداوم شما به میزبانی Firebase متکی است، برای اجرای firebase emulators:exec باید با استفاده از یک نشانه وارد شوید. سایر شبیه سازها نیازی به ورود ندارند.
برای تولید یک توکن، firebase login:ci در محیط محلی خود اجرا کنید. این نباید از یک سیستم CI انجام شود. دستورالعمل ها را برای احراز هویت دنبال کنید. شما فقط باید این مرحله را یک بار در هر پروژه انجام دهید، زیرا توکن در تمام بیلدها معتبر خواهد بود. توکن باید مانند یک رمز عبور رفتار شود. مطمئن شوید که مخفی بماند
اگر محیط CI شما به شما اجازه می دهد که متغیرهای محیطی را مشخص کنید که می توانند در اسکریپت های ساخت استفاده شوند، به سادگی یک متغیر محیطی به نام FIREBASE_TOKEN ایجاد کنید که مقدار آن رشته نشانه دسترسی است. Firebase CLI به طور خودکار متغیر محیطی FIREBASE_TOKEN انتخاب می کند و شبیه سازها به درستی شروع به کار می کنند.
به عنوان آخرین راه حل، می توانید به سادگی توکن را در اسکریپت ساخت خود قرار دهید، اما مطمئن شوید که طرف های غیرقابل اعتماد دسترسی ندارند. برای این رویکرد سخت کد شده، میتوانید --token "YOUR_TOKEN_STRING_HERE" به فرمان firebase emulators:exec اضافه کنید.
بعدش چی؟
یک شروع سریع با استفاده از شبیه ساز Hosting با دنبال کردن کدهای وب Firebase اجرا کنید.
نحوه ساخت نمونه اولیه توابع HTTPS با استفاده از شبیه ساز Hosting همانطور که در راهنمای توابع میزبانی توضیح داده شده است.
تاریخ آخرین بهروزرسانی 2025-07-25 بهوقت ساعت هماهنگ جهانی.
[null,null,["تاریخ آخرین بهروزرسانی 2025-07-25 بهوقت ساعت هماهنگ جهانی."],[],[],null,["\u003cbr /\u003e\n\nBefore you start prototyping and testing your web app with the\nFirebase Hosting emulator, make sure that you [understand the overall Firebase Local Emulator Suite workflow](/docs/emulator-suite/connect_and_prototype?database=Firestore),\nand that you [install and configure](/docs/emulator-suite/install_and_configure)\nthe Local Emulator Suite and review its [CLI commands](/docs/emulator-suite/install_and_configure#startup).\n\nYou should also be familiar with the features and implementation workflow\nfor Firebase Hosting. Start with the\n[introduction to Firebase Hosting](/docs/hosting).\n\nWhat can I do with the Firebase Hosting emulator?\n\nThe Firebase Hosting emulator provides high-fidelity local emulation of\nHosting services, providing much of the functionality found in\n[production Hosting](/docs/hosting/quickstart). The Hosting emulator\nlets you:\n\n- Prototype your static sites and web apps without incurring storage or access charges\n- Prototype, test and debug HTTPS functions before deploying to your Hosting site\n- Test sites and web apps in containerized, continuous integration workflows.\n\nChoose a Firebase project\n\nThe Firebase Local Emulator Suite emulates products for a single Firebase project.\n\nTo select the project to use, before you start the emulators, in the CLI run\n`firebase use` in your working directory. Or, you can pass\nthe `--project` flag to each emulator\ncommand.\n| **Note:** It's generally a good practice to use one project ID for all emulator invocations, so the Emulator Suite UI, different product emulators, and all running instances of a particular emulator can communicate correctly in all cases. In fact, by default, the Local Emulator Suite will warn on detecting multiple project IDs in use, though you can override this behavior. For guidance on setting and managing project IDs, see the [Installation and configuration guide](/docs/emulator-suite/install_and_configure#project_id_configuration).\n\nLocal Emulator Suite supports emulation of *real* Firebase projects and\n*demo* projects.\n\n| Project type | Features | Use with emulators |\n|--------------|-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|\n| Real | A real Firebase project is one you created and configured (most likely via the Firebase console). Real projects have live resources, like database instances, storage buckets, functions, or any other resource you set up for that Firebase project. | When working with real Firebase projects, you can run emulators for any or all of the supported products. For any products you are not emulating, your apps and code will interact with the *live* resource (database instance, storage bucket, function, etc.). |\n| Demo | A demo Firebase project has no *real* Firebase configuration and no live resources. These projects are usually accessed via codelabs or other tutorials. Project IDs for demo projects have the `demo-` prefix. | When working with demo Firebase projects, your apps and code interact with emulators *only*. If your app attempts to interact with a resource for which an emulator isn't running, that code will fail. |\n\nWe recommend you use demo projects wherever possible. Benefits include:\n\n- Easier setup, since you can run the emulators without ever creating a Firebase project\n- Stronger safety, since if your code accidentally invokes non-emulated (production) resources, there is no chance of data change, usage and billing\n- Better offline support, since there is no need to access the internet to download your SDK configuration.\n\n| **Note:** If you want to emulate cross-service interactions such as database-triggered Cloud Functions or Rules that rely on Authentication you must make sure that the project ID in your code (in `initializeApp()`, etc.) matches the project ID used by the Firebase CLI.\n\nCore prototyping workflow\n\nIf you're making quick iterations or you want your app to interact with\nemulated backend project resources, you can test your Hosting content and\nconfig locally. When testing locally, Firebase serves your web app at a locally\nhosted URL.\n\n1. *(Optional)* By default, your locally hosted app will interact with *real* ,\n not *emulated* , project resources (functions, database, rules, etc.).\n You can instead optionally connect your app to use any *emulated* project\n resources that you've configured. Learn more:\n [Realtime Database](/docs/emulator-suite/connect_and_prototype?database=RTDB) \\|\n [Cloud Firestore](/docs/emulator-suite/connect_and_prototype?database=Firestore) \\|\n [Cloud Functions](/docs/emulator-suite/connect_functions)\n\n2. From the root of your local project directory, run the following command:\n\n ```\n firebase emulators:start\n ```\n3. Open your web app at the local URL returned by the CLI (usually\n `http://localhost:5000`).\n\n4. To update the local URL with changes, refresh your browser.\n\nTest from other local devices\n\nBy default, the emulators only respond to requests from `localhost`. This\nmeans that you'll be able to access your hosted content from your computer's web\nbrowser but not from other devices on your network. If you'd like to test from\nother local devices, configure your `firebase.json` like so: \n\n \"emulators\": {\n // ...\n\n \"hosting\": {\n \"port\": 5000,\n \"host\": \"0.0.0.0\"\n }\n }\n\nGenerate auth tokens for continuous integration workflows\n\nIf your continuous integration workflows rely on Firebase Hosting, then you will\nneed to log in using a token in order to run `firebase emulators:exec`. The\nother emulators do not require login.\n| **Note:** If you have configured hosting in `firebase.json` but do not need it in CI test setups, use the `--only` flag to `emulators:start` or `emulators:exec` to include only the emulators that you need.\n\nTo generate a token, run `firebase login:ci` on your local environment; this\nshould not be performed from a CI system. Follow instructions to authenticate.\nYou should only need to perform this step once per project, since the token will\nbe valid across builds. The token should be treated like a password; make sure\nit is kept secret.\n\nIf your CI environment allows you to specify environment variables that can be\nused in the build scripts, simply create an environment variable called\n`FIREBASE_TOKEN`, with the value being the access token string. The\nFirebase CLI will automatically pick up the `FIREBASE_TOKEN` environment\nvariable and the emulators will start properly.\n\nAs a last resort, you can simply include the token in your build script, but\nmake sure that untrusted parties do not have access. For this hard-coded\napproach, you can add `--token \"YOUR_TOKEN_STRING_HERE\"` to the\n`firebase emulators:exec` command.\n\nWhat next?\n\n- Run a quickstart using the Hosting emulator by following the [Firebase web\n codelab](/codelabs/firebase-web).\n- Understand how to prototype HTTPS functions using the Hosting emulator as described in the [Hosting guides for functions](/docs/hosting/functions).\n- For a curated set of videos and detailed how-to examples, follow the [Firebase Emulators Training Playlist](/learn/pathways/firebase-emulators)."]]