Next.js Discord

Discord Forum

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

Unanswered
Asian black bear posted this in #help-forum
Open in Discord
Asian black bearOP
"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();

5 Replies

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.
@tafutada777 do you use Windows? it could be Node.js related issue
Asian black bearOP
I use macbook and my node version is latest