Doubt: How can I use request and response, if is possible, how would inject that. By the way, we had two functions in the client and two in the browser respectively:
export function getRequest() {
return {};
}
export function getResponse() {
return {};
}
export function getRequest() {
return Zone.current.get('req') || {};
}
export function getResponse() {
return Zone.current.get('res') || {};
}
You'll have to pass down whatever things you want specifically:
In the HomeController just pass down some Custom_data (with whatever you want in it)
CustomData CUSTOM_DATA = new CustomData();
CUSTOM_DATA.cookies = Request.HttpContext.Request.Cookies;
// Prerender / Serialize application (with Universal)
var prerenderResult = await Prerenderer.RenderToString(
"/",
nodeServices,
new JavaScriptModuleExport(applicationBasePath + "/Client/dist/main-server"),
unencodedAbsoluteUrl,
unencodedPathAndQuery,
CUSTOM_DATA,
30000,
Request.PathBase.ToString()
);
In your main.server & main.server.aot add a provider for it, you can pull data down from params.data.
Make a new InjectionToken<string>('COOKIES'); for it, you'll have to @Inject('COOKIES') string cookies in your app to get them.
{
provide: COOKIES:
useValue: params.data.cookies
}
Sorry typed all that out quickly, but that's the jist of it!
In general I want to clean that up, I think if params is passed to the aspnetcoreEngine I could just by default pass cookies and a few basic things that are common, and provide them.
I need to fix transfer data as well.
Hello, Mr. Pieszk.
I tried to apply your model to cross data between server and client and I had some troubles.
I configured the custom-data, and main.server & main.server.aot like your example.
This custom-data I need to use in server and client.
But I can't get this data in the client . How can I get this custom-data in server and client ways?
When I tried to inject this provider in browser.app.module, there are no values.
Do I need to use a cache? How?
Thanks a lot for the prompt reply.
I ll give you my file exemple:
How can I inject the settings in mains.Browser equals mains.server?
Aways that I try to use Isettings I receive this message: No provider for ISettings!
I have a few nice updates coming to the aspnetcoreEngine and I'll be adding the TransferData class back in later tonight. I'll explain how you transfer data / state from server to browser when I push it up, sorry for the delay. I knew I forgot to add something crucial the other day 馃榾
I tried to do something like described here, but I can't get window.customData in the browser version.
https://github.com/aspnet/JavaScriptServices/tree/dev/src/Microsoft.AspNetCore.SpaServices#server-side-prerendering
I'm actually using Globals to pass all the meta data down, I have a working prototype for what we can use but it's on my laptop, hopefully tomorrow or Friday I'll have time and I can push it up for you!
PR #179 now includes the REQUEST object that both the server & client have access to. Of course the REQUEST object is only truly populated for the Server, but the Client has it's own dependency injected version of it that only has document.cookies.
You should be all set now :)
I just clone your git and made my exemple.
Please find for bacon.
We have the controller with customData, mainServer with provider and I can access this value in server-app, but in mainBrowser I can't access this data to provide it. How can I access in browser-app.
What I need to do?
Most helpful comment
I have a few nice updates coming to the aspnetcoreEngine and I'll be adding the TransferData class back in later tonight. I'll explain how you transfer data / state from server to browser when I push it up, sorry for the delay. I knew I forgot to add something crucial the other day 馃榾