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’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How can I overwrite the metadata url? #84

Open
jgtestw opened this issue May 8, 2024 · 2 comments
Open

How can I overwrite the metadata url? #84

jgtestw opened this issue May 8, 2024 · 2 comments

Comments

@jgtestw
Copy link

jgtestw commented May 8, 2024

Hi,

To cache the metadata in the browser, I want to be able to add a version number to the metadata url. What is the best way to overwrite the default metadata url? It defaults to the service name property. I am aware of the technique of generating metadata at compile time/start up time and writing it to a file. I'd rather not do that.

@russelg
Copy link

russelg commented Jul 26, 2024

I had to do similar, this is what I ended up with. I'm using Angular, so this may not apply for you. All AjaxAdapter have requestInterceptor, so you can do this for non-angular as well.
Here I'm adding a "?v=versionnumber" to the url, but you can also change the URL itself through the same method.

import { HttpRequest } from "@angular/common/http";
import { AjaxRequestInterceptor } from "breeze-client";
import { AjaxHttpClientAdapter } from "breeze-client/adapter-ajax-httpclient";
import { AjaxRequest } from "breeze-client/src/interface-registry";

const metadataCacheBustRequestInterceptor: AjaxRequestInterceptor = Object.assign(
    // AjaxRequest interface does not include the "request" param, it's added by AjaxHttpClientAdapter
    (req: AjaxRequest & { request: HttpRequest<null> }) => {
        // add a cache-busting query param for metadata
        if (req.request.url.endsWith("/Metadata")) {
            const params = req.request.params.set("v", "version string goes here!!!!!!!!!!");
            req.request = req.request.clone({ params });
        }
    },
    // will only run on the first request (i.e. Metadata)
    { oneTime: true },
);

// other breeze initialisation etc... goes here

// httpclient is an instance of angular HttpClient
const ajaxAdapter = AjaxHttpClientAdapter.register(httpClient);
ajaxAdapter.requestInterceptor = metadataCacheBustRequestInterceptor;

@iz-iznogood
Copy link

One approach I used when I implemented a POS system that needed to work fully offline was to cache the metadata (along with data) in indexed db and when I needed to load the metadata, i used the MetadataStore.importMetadata.
However I was not on .Net so I am not sure if you can generate the metadata from .Net and send them to the server using another call (for caching)
I also had to use a version field like you, the above approach worked

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants