13.1.1 • Published 2 years ago

@nguniversal/hapi-engine v13.1.1

Weekly downloads
1,452
License
MIT
Repository
github
Last release
2 years ago

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.

13.1.1

2 years ago

13.1.0

2 years ago

13.0.2

2 years ago

13.1.0-next.1

2 years ago

13.0.1

2 years ago

13.0.0

3 years ago

13.0.0-rc.2

3 years ago

12.1.3

3 years ago

13.1.0-next.0

3 years ago

12.1.2

3 years ago

13.0.0-rc.1

3 years ago

13.0.0-rc.0

3 years ago

12.1.1

3 years ago

12.1.0

3 years ago

12.1.0-next.0

3 years ago

12.0.2

3 years ago

12.0.1

3 years ago

12.0.0

3 years ago

12.0.0-rc.1

3 years ago

12.0.0-rc.0

3 years ago

12.0.0-next.1

3 years ago

11.2.1

3 years ago

12.0.0-next.0

3 years ago

11.2.0

3 years ago

11.1.2

3 years ago

11.1.1

3 years ago

11.1.0

3 years ago

11.1.0-next.0

3 years ago

11.0.1

3 years ago

11.0.0

3 years ago

11.0.0-rc.0

3 years ago

11.0.0-next.2

4 years ago

11.0.0-next.1

4 years ago

11.0.0-next.0

4 years ago

10.1.0

4 years ago

10.1.0-rc.0

4 years ago

10.0.2

4 years ago

10.0.1

4 years ago

10.0.0

4 years ago

10.0.0-rc.1

4 years ago

10.0.0-rc.0

4 years ago

10.0.0-next.0

4 years ago

9.1.1

4 years ago

9.1.0

4 years ago

9.0.2

4 years ago

9.0.1

4 years ago

9.0.0

4 years ago

9.0.0-rc.2

4 years ago

9.0.0-rc.1

4 years ago

9.0.0-rc.0

4 years ago

9.0.0-next.14

4 years ago

9.0.0-next.13

4 years ago

8.2.6

4 years ago

8.2.5

4 years ago

9.0.0-next.9

4 years ago

9.0.0-next.8

4 years ago

9.0.0-next.7

4 years ago

9.0.0-next.6

5 years ago

9.0.0-next.5

5 years ago

9.0.0-next.3

5 years ago

9.0.0-next.2

5 years ago

9.0.0-next.1

5 years ago

9.0.0-next.0

5 years ago

8.1.1

5 years ago

8.1.0

5 years ago

8.0.0-rc.1

5 years ago

8.0.0-rc.0

5 years ago

8.0.0-beta.0

5 years ago

7.1.1

5 years ago

7.1.0

5 years ago

0.0.0

5 years ago

7.0.2

6 years ago

7.0.1

6 years ago

7.0.0

6 years ago

7.0.0-rc.0

6 years ago

6.1.0

6 years ago

6.0.0

6 years ago

6.0.0-rc.2

6 years ago

6.0.0-rc.1

6 years ago

6.0.0-rc.0

6 years ago

5.0.0

6 years ago

5.0.0-beta.8

6 years ago

5.0.0-beta.7

6 years ago

5.0.0-beta.6

6 years ago

5.0.0-beta.5

7 years ago

5.0.0-beta.4

7 years ago

5.0.0-beta.3

7 years ago

5.0.0-beta.2

7 years ago

5.0.0-beta.1

7 years ago

5.0.0-beta.0

7 years ago

1.0.0-beta.3

7 years ago