Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

More options to handle index.html cache control #297

Open
RobertoPrevato opened this issue Jan 2, 2023 · 1 comment
Open

More options to handle index.html cache control #297

RobertoPrevato opened this issue Jan 2, 2023 · 1 comment
Assignees
Labels
document Something worth documenting enhancement New feature or request

Comments

@RobertoPrevato
Copy link
Member

RobertoPrevato commented Jan 2, 2023

馃殌 Feature Request

    app.UseSpa(spa => {
        spa.Options.SourcePath = "ClientApp";

        spa.Options.DefaultPageStaticFileOptions = new StaticFileOptions() {
            OnPrepareResponse = ctx => {
                // Do not cache default page index.html
                var headers = ctx.Context.Response.GetTypedHeaders();
                headers.CacheControl = new CacheControlHeaderValue {
                    NoStore = true,
                    NoCache = true,
                };
            },
        };

        if (env.IsDevelopment()) {
            //spa.UseAngularCliServer(npmScript: "start");
            spa.UseProxyToSpaDevelopmentServer("http://localhost:4202");
        }
    });

Suggested by netwang @netwang 16:30 on gitter:

Above code is ASP.NET 6.0 code to configure the cache control of the static file index.html. NoStore and NoCache is better for index.html in Angular application. Could you check C# class CacheControlHeaderValue and add the similar function to BlackSheep?

@RobertoPrevato RobertoPrevato self-assigned this Mar 19, 2023
@RobertoPrevato RobertoPrevato added the enhancement New feature or request label Mar 19, 2023
@RobertoPrevato
Copy link
Member Author

RobertoPrevato commented Mar 19, 2023

@netwang
This feature is now available with https://pypi.org/project/blacksheep/2.0a4/

from blacksheep.server.files import DefaultFileOptions
from blacksheep.server.headers.cache import CacheControlHeaderValue

...

    app.serve_files(
        "app/static",
        fallback_document="index.html",
        default_file_options=DefaultFileOptions(
            cache_control=CacheControlHeaderValue(no_cache=True, no_store=True),
        ),
    )

@RobertoPrevato RobertoPrevato added the document Something worth documenting label Mar 19, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
document Something worth documenting enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

1 participant