BlazorStatic icon indicating copy to clipboard operation
BlazorStatic copied to clipboard

Configuration

Open ollih1980 opened this issue 1 year ago • 22 comments

Hello,

How to configure the path to the razor pages? I'm getting the following error:

System.IO.DirectoryNotFoundException: Could not find a part of the path '/app/Components/Pages'.

Thanks!

ollih1980 avatar Aug 16 '24 07:08 ollih1980

You probably use absolute path, try this instead: app/Components/Pages.

Did that help?

With the upcoming version it will find all the .razor pages automatically, so there will be no need to specify the RazorPagesPaths... We considered also to ignore certain paths, is that something you would use?

The new version is almost ready, but we can squeeze more into that https://github.com/tesar-tech/BlazorStatic/blob/master/BlazorStaticWebsite/Content/Blog/release-1.0.0-beta.10.md

tesar-tech avatar Aug 16 '24 11:08 tesar-tech

yes, I've added

builder.Services.AddBlazorStaticService(opt => {
    opt.RazorPagesPaths.Clear();
    opt.RazorPagesPaths.Add("Pages"); 
});

And now it's proceeding. But getting an additional error

BlazorStatic.Services.BlazorStaticService: Warning: Failed to retrieve page at Redirect. StatusCode:(null). Error: IPv4 address 0.0.0.0 and IPv6 address ::0 are unspecified addresses that cannot be used as a target address. (Parameter 'hostName') ([::]:443)
      Failed to retrieve page at Redirect. StatusCode:(null). Error: IPv4 address 0.0.0.0 and IPv6 address ::0 are unspecified addresses that cannot be used as a target address. (Parameter 'hostName') ([::]:443)

ollih1980 avatar Aug 16 '24 11:08 ollih1980

Can you tell me more about the setup? Where is it running? How is it running?

On what ip address is it supposed to run?

When you call UseBlazorStaticGenerator it find the first address from the WebApplication. See this line:

https://github.com/tesar-tech/BlazorStatic/blob/2d62ad4328c47530104084704de5572537fa84c9/src/BlazorStaticExtensions.cs#L144

Maybe that's not sufficient for your case.

tesar-tech avatar Aug 16 '24 12:08 tesar-tech

It's running in a local docker container (base mcr.microsoft.com/dotnet/aspnet:8.0). Docker in running on a windows host (VS 2022). IP Adresse will change depending on avalibility and docker config. Maybe could be a option to implement a fallback like 127.0.0.1 if the IP is 0.0.0.0.

ollih1980 avatar Aug 16 '24 12:08 ollih1980

Oh, yeah. I see, I see. So it takes the "inner" ip address, not the one exposed by docker, right?

What about option to configure the url?

builder.Services.AddBlazorStaticService(opt => {
    opt.AppUrl = "127.0.0.1"
});

would that work for you?

Can you think of an another approach?

The 127.0.0.1 might not work, because we also need a port, don't we?

How urgent is that for you now? I can promis, it will be solved in a near future. It is definitely issue that needs to be solved...

tesar-tech avatar Aug 16 '24 12:08 tesar-tech

Port seems to be correct, as in the error message. But IP may also change during the lifecycle. It would be good to get the IP adress from the system... Let me think how to get it. I will create a PR for this.

ollih1980 avatar Aug 16 '24 12:08 ollih1980

With some code changes I got it to work. (PR: https://github.com/tesar-tech/BlazorStatic/pull/25) But now getting an additional error in the generated index.html An unhandled exception has occurred. See browser dev tools for details.

But I can't click on this... as this is in the generated file. Any idea?

ollih1980 avatar Aug 18 '24 13:08 ollih1980

I am afraid we are trying to solve two things -> Running the app inside the docker and whatever specific you have in your codebase... But we'll get there no matter what.

  • Can you run the app (not killing it after file generation)? Is the issue only in the generated file?
  • maybe you want to set the ASPNETCORE_ENVIRONMENT to Development, thus it should tell you more..
  • You should be able to see the error messages in console where it runs the app...
  • Does it work for you when you hardcode the appurl to 127.0.0.1:APP_PORT ?

Can you provide me with a simple Dockerfile configuration? I will try to run the minimal app in the docker and see if something has change....

If you could invite me to the repo where you trying to solve the issues, it would also allow us to proceed faster (but of course I understand you cannot)

tesar-tech avatar Aug 18 '24 15:08 tesar-tech

  • Can you run the app (not killing it after file generation)? Is the issue only in the generated file?
  • ---> Yes, only in the generated file
  • maybe you want to set the ASPNETCORE_ENVIRONMENT to Development, thus it should tell you more..
  • --> set this. But no further output, no additional messages. There are no error messages at all
  • You should be able to see the error messages in console where it runs the app...
  • --> no error messages
  • Does it work for you when you hardcode the appurl to 127.0.0.1:APP_PORT ?
  • -->this was my first try. I hard coded it and with deactivation of SSL cert check it worked... at least no error messages

ollih1980 avatar Aug 19 '24 05:08 ollih1980

Docker File:

#See https://aka.ms/customizecontainer to learn how to customize your debug container and how Visual Studio uses this Dockerfile to build your images for faster debugging.

FROM mcr.microsoft.com/dotnet/aspnet:8.0 AS base
WORKDIR /app
EXPOSE 80
EXPOSE 443

FROM mcr.microsoft.com/dotnet/sdk:8.0 AS build
WORKDIR /src
COPY ["Test/Test.csproj", "Test/"]
RUN dotnet restore "Test/Test.csproj"
COPY . .
WORKDIR "/src/Test"
RUN dotnet build "Test.csproj" -c Release -o /app/build

FROM build AS publish
RUN dotnet publish "Test.csproj" -c Release -o /app/publish /p:UseAppHost=false

FROM base AS final
WORKDIR /app
COPY --from=publish /app/publish .
ENTRYPOINT ["dotnet", "Test.dll"]

ollih1980 avatar Aug 19 '24 05:08 ollih1980

I think the problem is, that the with the use of httpclient a new "Webbrowser" instance gets created and I've a lot of models and dynamic data within my components. Even there is a need to login before accessing the page. With the new instance all those data got lost.

ollih1980 avatar Aug 19 '24 05:08 ollih1980

Ok. So I have added the default docker file that Rider throwed at me,.. And it seems to be working quite well:

image The output folder contains everything it is supposed to. Also the logs have no issues

info: BlazorStatic.Services.BlazorStaticService[0]
2024-08-19T12:29:25.283187581Z       Generating tags/test into tags/test.html
2024-08-19T12:29:25.296622066Z info: BlazorStatic.Services.BlazorStaticService[0]
2024-08-19T12:29:25.296671821Z       Generating projects/project1 into projects/project1.html
2024-08-19T12:29:25.312444698Z info: BlazorStatic.Services.BlazorStaticService[0]
2024-08-19T12:29:25.312517366Z       Generating projects/project2 into projects/project2.html

also the app is running on http://127.0.0.1:8080/

I pushed the dockerfile, you can compare the differences with your real setup..

I guess it works because of your addition with changing the address...

What exactly is your setup and desired outcome? You have a Blazor app which just runs and you trying to generate state pages out of it? What exactly means this: -->this was my first try. I hard coded it and with deactivation of SSL cert check it worked... at least no error messages - were you able to generate the static pages?

tesar-tech avatar Aug 19 '24 12:08 tesar-tech

The logs are looking the same:

info: BlazorStatic.Services.BlazorStaticService[0]
      Generating /Index into /Index/index.html
BlazorStatic.Services.BlazorStaticService: Information: Generating /Index into /Index/index.html
BlazorStatic.Services.BlazorStaticService: Information: Generating / into /index.html
info: BlazorStatic.Services.BlazorStaticService[0]
      Generating / into /index.html
info: BlazorStatic.Services.BlazorStaticService[0]
      Generating /Redirect into /Redirect/index.html
BlazorStatic.Services.BlazorStaticService: Information: Generating /Redirect into /Redirect/index.html

Also folder structure looks okay to me: image

but the index.html looks like this:

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="utf-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <base href="/" />
    <link href="css/site.css" rel="stylesheet" />
    <link href="css/table.css" rel="stylesheet" />
    <link href="QwikMinutes.styles.css" rel="stylesheet" />
    <link href="https://fonts.googleapis.com/css?family=Roboto:300,400,500,700&display=swap" rel="stylesheet" />
    <link href="_content/MudBlazor/MudBlazor.min.css" rel="stylesheet" />
    <!--Blazor:{"type":"server","key":{"locationHash":"77D12F14A8105320B1AAED6AE7E689DA0EC4483270A645E84079EAA0FFDF550D:0","formattedComponentKey":""},"sequence":0,"descriptor":"CfDJ8KoYn7aGcp1Hpe96wgFomap4Y\u002BU1V2HFdBgE2ETvSoqecLumAWMYESW05I4RDpYZNSqfOUeKejFvd13evaufyUbhyX4aa2ePHtKkrNW/a6X9PU1NqW\u002BdAMcNvasQXMCQ8iePayGUDaDhhrlBUa7xDhnRpnVAG5kjSOFk4Hrg7SlZ4efRs2C4cbrVOiObDGxQ5fcrOJvS/\u002BbWHvcxHUVpHTnae55W2qevBR44b/ZayamEmNk3UAckquoXpPMfa/1Zd5/J5GU6ooUKPU\u002BCsI6j0SkommAv0jnhMbGprvjyL8dh/OMAYXNmlVWtiKTVdvT5GM51WWOCHxE9k1ruHh\u002BdHso7fekg9M3H84P5LO2YVQbeNCiDWVjrJBA/gyu30qPFfR2AZ2FdijZPtJ2r3U6XMuuAkQHgjdt4eBja4i8HcfvfSgRBE5jzql3\u002B81UZ0TyvWNhTvK\u002BGbdRKnafAXvz/69cPuYTmuGqX5AK7C7emo/IPYXx69On1yd/ibr7w31rb10ZRrsP8CFF/LCnwA5vta9IMHZrjBtDAWx/CJboSumdT1m64NLzEdN0OKyg46tT4jd2H3UKs8N7Jptnjw1vjCkE="}-->
</head>
<body>
    

<!--Blazor:{"type":"server","key":{"locationHash":"F345E049F19A430A8EFD090751D1D91F9482BBE5173CE83DC6F8C011E3E96AE2:0","formattedComponentKey":""},"sequence":1,"descriptor":"CfDJ8KoYn7aGcp1Hpe96wgFomapCy74YFNDihD9g0DGeJL20q3HDCASurX2lV/EXZC38cz7Qc\u002B0ahuLgo6B3tBaCjeW/32c8eAQ3wJudbmgKuyyJQhjejsLeIqcNcXGrotDaA2TGIubsXnIVh2VB5RoYkGxoIAk8BvkXYnu3ndJLzcm9wXr8IYE7TU9\u002B\u002BdMmWTxx/Uh\u002B9pe0IoHf2XhUbA99ZxhPPuEB6OlJxAf21zfenSSsPM8MMgWekfN/xwBn9EUAcAc43Ano5Ik0rWqQvqdje7OiQ9SR1xI1yDoQVyw5VyswETBac7fsUQbs55Yu18QiFINn3YlnLxsK4IHTml4fkFcs0coRxw99lmfZ/BmWUqxADDteuWeIyHATOJKBGqU0KT\u002BBBpnpmYLoHjS/Bfo6gZZ8o8d4aYi3z2WcZsaGE7clU7azYerKvpr83FxuFo8Y2lRrnTZoOM1t3d0ukDgLxo6PL1gG/ykol7GoNaVQMYMxrWInCjtsms88ZTuT6yKjPQ=="}-->
<link href="https://fonts.googleapis.com/css?family=Roboto:300,400,500,700&display=swap" rel="stylesheet" />
<link href="_content/MudBlazor/MudBlazor.min.css" rel="stylesheet" />
<body>

</body>
<script src="_content/MudBlazor/MudBlazor.min.js"></script>
    <div id="blazor-error-ui">
        
        
            An unhandled exception has occurred. See browser dev tools for details.
        
        <a href="" class="reload">Reload</a>
        <a class="dismiss">🗙</a>
    </div>
    <script src="_framework/blazor.server.js"></script>
    <script src="_content/MudBlazor/MudBlazor.min.js"></script>
    <script src="https://code.jquery.com/jquery-3.7.1.min.js"></script>
</body>
</html>
<script>
    function BlazorDownloadFile(filename, contentType, content) {
        // Create the URL
        const file = new File([content], filename, { type: contentType });
        const exportUrl = URL.createObjectURL(file);

        // Create the <a> element and click on it
        const a = document.createElement("a");
        document.body.appendChild(a);
        a.href = exportUrl;
        a.download = filename;
        a.target = "_self";
        a.click();

        // We don't need to keep the object URL, let's release the memory
        // On older versions of Safari, it seems you need to comment this line...
        URL.revokeObjectURL(exportUrl);
    }

    window.getDivContents = (element) => {
        return element.innerHTML;
    }
</script>

ollih1980 avatar Aug 20 '24 04:08 ollih1980

  • Isn't your page server interactive?
  • What happens if you access the page through the browser when the app is running?

tesar-tech avatar Aug 20 '24 06:08 tesar-tech

What do you mean by interactive? My app creates a some kind of reports after the user uploaded the data. The data is stored in different models. When I access the page, I need to login first, via SSO Auth, then I can access the page and create the reports, after this I would like to access the static html with all the content generated.

ollih1980 avatar Aug 20 '24 08:08 ollih1980

I mean Blazor Server interactivity. Because BlazorStatic is meant to be used with SSR, mainly from the reasons that it is more straightforward.

btw the <div id="blazor-error-ui"> is always there, it is just made visible when something wrong happens.. In your html you also have multiple <body> tags and they are arranged quite weirdly... I don't know what is causing this..

The auth will be an issue here, because obviously the httpClient isn't authorized. But there are ways how to do it.

tesar-tech avatar Aug 20 '24 12:08 tesar-tech

I think the logon is a blocking issue. The Auth is handled via SSO and the only way, I can think of, to solve this is to transfer the current session, incl. models, data etc. Any idea how to handle this?

ollih1980 avatar Aug 21 '24 05:08 ollih1980

I guess you probably need something like this:

var httpClient = new HttpClient();
httpClient.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", "your_token_here");

I can let users to define their own HttpClient instead of creating new one by BlazorStatic. With that is should be pretty straightforward to setup everything.

Can you try to hardcode the token for now and test the solution?

tesar-tech avatar Aug 21 '24 17:08 tesar-tech

I ran into the "Pages problem" myself. Looking forward to not needing to specify them. I'm not using markdown files in this project so I had to list all the routes.

Example: options.PagesToGenerate.Add(new("src/Components/Pages/About", "/about/index.html"));

Pro Tip related to building Pages: for the launch profile to run on your build server, use http instead of https. Everything worked locally because dev certs were in place, but it failed in the build pipeline. Actually, the build "worked", but only the main index.html was produced. The other pages didn't make it. The logs had an error about SSL which led me to the solution. I suppose you could also install dev-certs as part of the pipeline, but I didn't explore that option.

The launch profile in the docs works: https://tesar-tech.github.io/BlazorStatic/docs/deployment

kijanawoodard avatar Aug 28 '24 21:08 kijanawoodard

Hey @kijanawoodard . New version is alive . Please let me know how it works.

I would like to discuss the http vs https, but it is OT here. Can you create new issue or rise the topic on discord?

tesar-tech avatar Aug 30 '24 12:08 tesar-tech

@ollih1980 Any progress on this?

tesar-tech avatar Aug 30 '24 12:08 tesar-tech

Hey @kijanawoodard . New version is alive . Please let me know how it works.

Upgraded to beta10 and removed all my custom page route code. Works!

kijanawoodard avatar Aug 31 '24 22:08 kijanawoodard