1
votes

I am developing an app with Blazor WebAssembly using the ASP.NET Core hosted model (so 3 projects: Client, Server, Shared) that connects to a Firestore database and am having trouble getting the Server-side working when deployed to Firebase. Server-side/Firestore code works fine when the app is run locally with IIS Express.

When publishing in VS, I just publish the Server project since the Client files are linked and published along with it. Once deployed, any Client code works fine, but anything related to Firestore does not (since the API controllers are in the Server project).

I've scoured every article on the subject but most are outdated since Blazor WASM has changed so much since the previews.

Has anyone successfully done this? Am I missing a step or is Firebase just not set up to work with ASP.NET/Blazor Server-side stuff?

Here is my Startup.cs in case it helps - it's pretty much just the default one provided by the Blazor WebAssembly ASP.NET Core hosted template:

using Microsoft.AspNetCore.Builder;
using Microsoft.AspNetCore.Hosting;
using Microsoft.AspNetCore.HttpsPolicy;
using Microsoft.AspNetCore.ResponseCompression;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Hosting;
using System.Linq;

namespace G01ElectronicVoting.Server
{
    public class Startup
    {
        public Startup(IConfiguration configuration)
        {
            Configuration = configuration;
        }

        public IConfiguration Configuration { get; }

        // This method gets called by the runtime. Use this method to add services to the container.
        // For more information on how to configure your application, visit https://go.microsoft.com/fwlink/?LinkID=398940
        public void ConfigureServices(IServiceCollection services)
        {

            services.AddControllersWithViews();
            services.AddRazorPages();
        }

        // This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
        public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
        {
            if (env.IsDevelopment())
            {
                app.UseDeveloperExceptionPage();
                app.UseWebAssemblyDebugging();
            }
            else
            {
                app.UseExceptionHandler("/Error");
                // The default HSTS value is 30 days. You may want to change this for production scenarios, see https://aka.ms/aspnetcore-hsts.
                app.UseHsts();
            }

            app.UseHttpsRedirection();
            app.UseBlazorFrameworkFiles();
            app.UseStaticFiles();

            app.UseRouting();

            app.UseEndpoints(endpoints =>
            {
                endpoints.MapRazorPages();
                endpoints.MapControllers();
                endpoints.MapFallbackToFile("index.html");
            });
        }
    }
}

EDIT: This is all to avoid paying for Azure

1

1 Answers

2
votes

Firebase Hosting on its own only serves static assets, and does not interpret anything of your files on its servers.

Firebase Hosting is integrated with Cloud Functions, through which you can run any language that supports (currently only Node.js).

Firebase Hosting is also integrated with Google Cloud Run, which supports a much broader range of runtimes. I even see some mention of folks running .NET Core in these search results, so that might be your best path forward.