Skip to content
This repository was archived by the owner on Apr 8, 2020. It is now read-only.

Conversation

laskoviymishka
Copy link
Contributor

@laskoviymishka laskoviymishka commented May 6, 2016

Work in progress.
Created basic sample for reproducing issue #66 also some refactor to #68.

@laskoviymishka laskoviymishka changed the title wip: Cookies issue wip: Cookies issue rel #66 May 6, 2016
@laskoviymishka laskoviymishka changed the title wip: Cookies issue rel #66 wip: Cookies issue May 6, 2016
@laskoviymishka
Copy link
Contributor Author

Implement basic cookie pushing from server to boot function. Also refactor a little bit prerender process to enable payload passing from server request to boot function also (related to issue #68)
CC @SteveSandersonMS

@angelyordanov
Copy link

angelyordanov commented May 11, 2016

Hey @laskoviymishka, great work!
Just a few notes though.

  1. Changing the code style of files you are not editing makes it harder to track your changes.
  2. Isn't it better the new method in the Prerenderer to accept the PrerendererOptions as an argument, not just forward the call to the INodeServices. After all its idea is to be a wrapper of the aspnet-prerendering module.

@laskoviymishka
Copy link
Contributor Author

Hi @angelyordanov, thx for feedback

  1. Visual studio change code style, and I didn't mention it, my bad. IMHO this repo code should be adjusted to common ms code style rules for c#. Right now code unreadable.
  2. I don't see any reason why this static Prerenderer class should be here, i should remove it at all. Right now it not used at all. May be it better to extract prerendering functionality from PrerenderTagHelper to some IPrerenderer which will be registred in ServicesCollection so it could be accessed anywhere, not just tag helper. Any thoughts on this?

This is still in progress, so any feedback is highly appreciated.

@angelyordanov
Copy link

I tried to imagine what would an IPrerenderer interface look like, and what would be the benefit of replacing it through the DI subsystem and the only thing I could think of is if one wants to substitute the aspnet-prerendering module with its own renderToString implementation(removing domain-tasks, webpack building, etc..). But then we need to somehow generalize the PrerenderTagHelper's attributes and the way they are passed to the IPrerenderer.

Anyway, if one wants to do that he can just copy the PrerenderTagHelper + Prerenderer and start from there. Its not that much code.

So, You are right, the Prerenderer is an implementation detail and is probably best removed or made internal.

- Introduce prerenderer interface
- Extract classes to separate files
- Remove static accessor to prerenderer
- Clean prerender options
- Remove magic callback setter to prior manual population of args
- Add basic payload population for sample
@laskoviymishka
Copy link
Contributor Author

laskoviymishka commented May 12, 2016

Refactor prerenderer a little bit:

  • Introduce prerenderer interface
  • Extract classes to separate files
  • Remove static accessor to prerenderer
  • Clean prerender options
  • Remove magic callback setter to prior manual population of args
  • Add basic payload population for ng2 auth sample

So now basic setup is not require add node services anymore, but you could modify some prerendering options with following code in your startup:

public void ConfigureServices(IServiceCollection services)
{
          services.AddPrerender(
                    r => new PrerenderOptions
                    {
                              /* your project specific options goes here */
                    });
}

Also not it much easier to pass some data from server direct to your boot JS function. Here is sample:

public void ConfigureServices(IServiceCollection services)
{
          services.AddPrerender(
                    r => new PrerenderOptions
                    {
                              PayloadProvider = context => new object[]
                              {
                                  "hello i'm payload from server",
                                  "my is also from server, but i'm, unicorn",
                                  new { name = "Pink", type = "Fluffy", race = "Unicorn" }
                              }
                    });
}

In this callback scope there avaible service provider and http context object, so it could be pretty easy to extract this population to somekind of service. Here is sample:

public void ConfigureServices(IServiceCollection services)
{
          services.AddPrerender(
                    provider => new PrerenderOptions
                    {
                              PayloadProvider = provider.GetServices<IInitialStateService>().PopulatePayload
                    });
}

Folks, any thoughts on this?

@laskoviymishka laskoviymishka changed the title wip: Cookies issue wip: Cookies issue + pipeline hooks May 12, 2016
@laskoviymishka laskoviymishka changed the title wip: Cookies issue + pipeline hooks wip: Cookies issue and payload provider May 12, 2016
@laskoviymishka
Copy link
Contributor Author

Merge rc2 upgrade into this quite painfull, better to recreate it as new PR.

@jeinz11
Copy link

jeinz11 commented May 28, 2017

how to use this addPrerender it says the addPrerender does not exist thanks

@laskoviymishka
Copy link
Contributor Author

This pr was not merged and proposed api is not in mainline yet

@jeinz11
Copy link

jeinz11 commented May 28, 2017

oh no...im stuck right now passing cookie to my api controller during SSR do you have any solutions? thanks

@laskoviymishka
Copy link
Contributor Author

There is a solution but with a slightly different api. It should be described in docs page

@jeinz11
Copy link

jeinz11 commented May 28, 2017

thanks i was trying to pass it in my redux state by using this code

    const store = configureStore({ currentUser: { isUserLoggedIn: false,userCookie:"asdasdasdsdas" } });

but when the time i retrieve... it doesnt change the value when doing SSR please help huhuhuhu

@jeinz11
Copy link

jeinz11 commented May 29, 2017

@laskoviymishka please help me sir

@laskoviymishka
Copy link
Contributor Author

You should use asp-prerender-data attribute of tag helper to pass cookie data to your js code. Then in js code you should register some opaque token for that and that it.

@laskoviymishka
Copy link
Contributor Author

On client side there is

export interface BootFuncParams {
    location: url.Url;          // e.g., Location object containing information '/some/path'
    origin: string;             // e.g., 'https://example.com:1234'
    url: string;                // e.g., '/some/path'
    absoluteUrl: string;        // e.g., 'https://example.com:1234/some/path'
    domainTasks: Promise<any>;
    data: any;                  // any custom object passed through from .NET
}

Object available. This object may contain your HttpContext.Request.Cookies

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

Successfully merging this pull request may close these issues.

4 participants