Skip to content

sketch7/aspnet-prerendering

Repository files navigation

@ssv/aspnet-prerendering

CI npm version

Port of aspnet-prerendering which supports ESM.

This allows using vite/esbuild angular (was tested only with angular - @angular-devkit/build-angular:application)

Quick links

Change logs | Project Repository

Installation

Get library via npm

npm install @ssv/aspnet-prerendering

Usage

import { renderModule } from "@angular/platform-server";
import { APP_BASE_HREF } from "@angular/common";
// import { createServerRenderer } from "aspnet-prerendering";
import { createServerRenderer } from "@ssv/aspnet-prerendering";

import { AppServerModule } from "./app/app.server.module";

interface TransferData {
  originalHtml: string;
  startupContext: StartupContext; // custom
  request: any;
}

export default createServerRenderer(params => {
  const { startupContext, originalHtml } = params.data as TransferData;
  const extraProviders = [
    { provide: APP_BASE_HREF, useValue: startupContext.virtualPath },
    { provide: "BASE_URL", useValue: params.origin + params.baseUrl },
  ];

  const options = {
    document: originalHtml,
    url: params.url,
    extraProviders
  };

  const renderPromise = renderModule(AppServerModule, options);

  return renderPromise.then(html => ({ html }));
});

Contributions

Check out the development guide.

About

ASPNET SPA Services ESM compatible

Resources

License

Stars

Watchers

Forks

Packages

No packages published