Reputation: 141
I decided to add ssr capability with nextjs to the project that started with asp.net core react template in visual studio. Before adding nextjs when I clicked on the run project button in visual studio both api server and cra server would've started without any problems...but after adding next to my project it gives me a server error.
I fixed that by running npm run dev
or npm start
in vs code to start nextjs server alongside visual studio.
And now that I want to publish my project in visual studio there is no clientApp or any other react related folder in my published folder ( and of course it gives internal server error when uploaded to server and looks like it doesn't even build my nextjs app )
How can I publish my nextjs app based on visual studio asp.net core react template?
Upvotes: 2
Views: 9353
Reputation: 437
What worked for me was using the NextjsStaticHosting-AspNetCore Following the the steps below:
Add the package using dotnet add package NextjsStaticHosting.AspNetCore --version 0.9.2-preview
.
Add Next.js hosting support:
services.Configure<NextjsStaticHostingOptions(config.GetSection("NextjsStaticHosting")); services.AddNextjsStaticHosting();
Add the following section on appsettings.json:
"NextjsStaticHosting": {"RootPath": "client-app"}
Add the following command on package.json
"build:export": "npx next build && npx next export -o build/"
Update your build command on your .csproj file to the following:
<Exec WorkingDirectory="$(SpaRoot)" Command="npm run build:export" />
Upvotes: 0
Reputation: 138
You need to use reverse proxy
: https://learn.microsoft.com/en-us/aspnet/core/host-and-deploy/linux-nginx?view=aspnetcore-3.1
Upvotes: 1