Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@nguniversal/hapi-engine

Package Overview
Dependencies
Maintainers
2
Versions
93
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@nguniversal/hapi-engine

Hapi Engine for running Server Angular Apps

  • 13.1.1
  • latest
  • v13-lts
  • Source
  • npm
  • Socket score

Version published
Maintainers
2
Created
Source

Angular Hapi Engine

This is a Hapi Engine for running Angular Apps on the server for server side rendering.

Deprecated

This package has been deprecated. Please use @nguniversal/common instead.

Usage

npm install @nguniversal/hapi-engine --save

To use it, set the engine and then route requests to it

import { Request, Server } from 'hapi';
import { ngHapiEngine } from '@nguniversal/hapi-engine';

const server = new Server();
server.connection({
  host: 'localhost',
  port: 8000,
});

server.route({
  method: 'GET',
  path: '/{path*}',
  handler: (req: Request) => ngHapiEngine({ req, bootstrap: ServerAppModule }),
});

Configuring the URL and Document

It is possible to override the default URL and document fetched when the rendering engine is called. To do so, simply pass in a url and/or document string to the renderer as follows:

server.route({
  method: 'GET',
  path: '/{path*}',
  handler: (req: Request) => {
    const url = 'http://someurl.com';
    const document = '<html><head><title>New doc</title></head></html>';
    return ngHapiEngine({
      req,
      url,
      document,
    });
  },
});

Extra Providers

Extra Providers can be provided either on engine setup

const hapiEngine = ngHapiEngine({
  bootstrap: ServerAppModule,
  providers: [ServerService],
});

Advanced Usage

Request based Bootstrap

The Bootstrap module as well as more providers can be passed on request

server.route({
  method: 'GET',
  path: '/{path*}',
  handler: (req: Request) =>
    ngHapiEngine({
      bootstrap: OtherServerAppModule,
      providers: [OtherServerService],
      req,
    }),
});

Using the Request and Response

The Request and Response objects are injected into the app via injection tokens. You can access them by @Inject

import { Request } from 'hapi';
import { REQUEST } from '@nguniversal/hapi-engine/tokens';

@Injectable()
export class RequestService {
  constructor(@Inject(REQUEST) private request: Request) {}
}

If your app runs on the client side too, you will have to provide your own versions of these in the client app.

Keywords

FAQs

Package last updated on 04 May 2022

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc