How can I Build a Blog App Using Blazor WASM and Strapi

47 Views Asked by At

I'm learning programming and trying to create a blog based on Blazor WASWM and I'd like to use Strapi as a cdn. But I can't connect Strapi (backend) with Blazor (frontend). I tried this guide but it only worked on the old version of .net: https://strapi.io/blog/how-to-build-a-blog-app-using-blazor-wasm-and-strapi

I added this code to strapi plugin.js:

module.exports = ({ env }) => ({
  'transformer': {
    enabled: true,
    config: {
      prefix: '/api/',
      responseTransforms: {
        removeAttributesKey: true,
        removeDataKey: true,
      }
    }
  },
});

And then installed strapi-plugin-transformer add content and gave public user all permisions That was all for backend(Strapi I think)

{
  "AppSettings": {
    "STRAPI_API_URL": "http://localhost:1337"
  }
}

and Models folder with AppSettings.cs Now about frontend, so I create appsetting.json in wwwroot folder:

namespace frontend.Models
{
    public class AppSettings
    {
        public string STRAPI_API_URL { get; set; }
    }
}

Modified Program.cs:

using Microsoft.AspNetCore.Components.Web;
using Microsoft.AspNetCore.Components.WebAssembly.Hosting;
using frontend.Models;

namespace frontend
{
    public class Program
    {
        public static async Task Main(string[] args)
        {
            var builder = WebAssemblyHostBuilder.CreateDefault(args);
            builder.RootComponents.Add<App>("#app");

            builder.Services.AddScoped(sp => new HttpClient { BaseAddress = new Uri(builder.HostEnvironment.BaseAddress) });

            await builder.Build().RunAsync();
        }

        public static void ConfigureServices(IServiceCollection services)
        {
            // Example of loading a configuration as configuration isn't available yet at this stage.
            services.AddSingleton(provider =>
            {
                var config = provider.GetService<IConfiguration>();
                return config.GetSection("App").Get<AppSettings>();
            });
        }
    }
}

And add

I tried doing it according to the tutorial and also upgrading this project https://github.com/Marktawa/tags-strapi-purplerhino and none of it worked for me.

If anyone know how to fix it or if you have a suggestion for a better alternative, I will only be glad.

0

There are 0 best solutions below