#.Net Core 7 backend developed but , it is not Working SSR Fetch in NextJS

6 messages · Page 1 of 1 (latest)

unreal galleon
#

"I have developed a WebApi using .Net Core 6. Now, I want to use these APIs in the FrontEnd with NextJS. While Server-Side Rendering, I cannot access the data and encounter errors, but I can access the data during Client-Side Rendering. How can I solve this?"

Here is my Program.cs

using OnionArch.Persistance;

var builder = WebApplication.CreateBuilder(args);

// Add services to the container.

builder.Services.AddControllers();
// Learn more about configuring Swagger/OpenAPI at https://aka.ms/aspnetcore/swashbuckle
builder.Services.AddEndpointsApiExplorer();
builder.Services.AddSwaggerGen();

builder.Services.AddPersistanceServices();

builder.Services.AddCors(options =>
{
options.AddPolicy("CorsPolicy", builder => builder.AllowAnyOrigin().AllowAnyMethod().AllowAnyHeader());
});

var app = builder.Build();

// Configure the HTTP request pipeline.
if (app.Environment.IsDevelopment())
{
app.UseCors();
app.UseSwagger();
app.UseSwaggerUI();
}
app.UseCors("CorsPolicy");

app.UseHttpsRedirection();

app.UseAuthorization();

app.MapControllers();

app.Run();

jovial roverBOT
#

🔎 This post has been indexed in our web forum and will be seen by search engines so other users can find it outside Discord

      🕵️ Your user profile is private by default and won't be visible to users outside Discord, if you want to be visible in the web forum you can add the "Public Profile" role in <id:customize>

      ✅ You can mark a message as the answer for your post with `Right click -> Apps -> Mark Solution`
      (if you don't see the option, try refreshing Discord with Ctrl + R)
cursive nexus
#

do you use Windows? it could be Node.js related issue

#

client side fetching runs on a web browser so no problem, while SSR runs on Node.js

#

plus some of versions of Node.js on Windows do not work so you might want to check the version

#

basically C# ASP.NET has nothing to do with it. say if you use a public endpoint such as pokemon, it would fail.