I am quite new to hosting processes. I connected to my Windows hosting through Plesk from my provider’s website and added the published codes of my backend API, which I created with .NET, into the httpdocs directory. Additionally, I created a folder named “frontend” inside httpdocs and placed my React build files there. My current issue is that I can access Swagger via the URL, but I cannot access any other pages. It’s as if my React files don’t exist, and I get a 404 error on screens like url/Login, for example.
When I do the opposite, i.e., place the React files in httpdocs and move the .NET files to a subfolder, the UI is displayed, but I cannot access the backend.
web.config :
<?xml version="1.0" encoding="UTF-8"?>
<configuration>
<system.webServer>
<rewrite>
<rules>
<!-- React Routes -->
<rule name="React Routes" stopProcessing="true">
<match url="^(?!backend/|api/|swagger/|frontend/|.*..*$).*$" />
<conditions logicalGrouping="MatchAll">
<add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true" />
<add input="{REQUEST_FILENAME}" matchType="IsDirectory" negate="true" />
</conditions>
<action type="Rewrite" url="/frontend/index.html" />
</rule>
<!-- API Routes -->
<rule name="API Routes" stopProcessing="true">
<match url="^api/(.*)" />
<conditions logicalGrouping="MatchAll">
<add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true" />
<add input="{REQUEST_FILENAME}" matchType="IsDirectory" negate="true" />
</conditions>
<action type="Rewrite" url="/{R:0}" />
</rule>
</rules>
</rewrite>
<handlers>
<add name="aspNetCore" path="*" verb="*" modules="AspNetCoreModuleV2" resourceType="Unspecified" />
</handlers>
<aspNetCore processPath="dotnet" arguments=".myapp.dll" stdoutLogEnabled="true" stdoutLogFile=".logsstdout" hostingModel="InProcess">
<environmentVariables>
<environmentVariable name="ASPNETCORE_ENVIRONMENT" value="Production" />
</environmentVariables>
</aspNetCore>
<httpErrors errorMode="Detailed" />
</system.webServer>
</configuration>
program.cs :
...
app.UseStaticFiles();
app.UseHttpsRedirection();
app.UseCors("corsapp");
app.UseRouting();
app.UseAuthentication();
app.UseAuthorization();
app.MapFallbackToFile("index.html");
app.MapControllers();
app.Run();
package.json has : “homepage”: “./”
Router.js :
enter image description here
index.js :
enter image description here
Please remember that I am someone who is trying to learn these processes. Could you give me some ideas on how to solve this problem?
I also tried the scenario I described above and putting everything inside httpdocs, but I couldn’t succeed.
mozal is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.